Malcolm Groves has a blog post up where he demonstrates how to convert the display of a field from an integer to a boolean with Delphi XE5 Firemonkey. Should also work with Delphi XE6 and AppMethod. The way it works is that the same field (IntegerField from the demo) is bound to to a column in a grid. There is an outbound property called CustomFormat and an inbount property called CustomParse. In the CustomFormat field you put ToStr(%s) <> “0” and in the CustomParse field you put IfThen(ToStr(%s) = “True”, -1, 0). The properties take kind of a macro language where %s is the value to be modified and then you can use various different functions on the value. In this case a To String function and a If Then function. There are more screenshots you can check out which will make it more clear. Check out the source code here. One of the comments from Mathias on the blog post points out a different way to accomplish the Integer to Boolean functionality with LiveBindings and it also includes a demo. One plus about this second demo is that it applies the integer to boolean conversion through your entire project instead of having to set it up for each field like the first method. Both of these methods should work cross platform on Android, IOS, Windows, and OSX. Here is some sample code from the second demo:
procedure RegisterOutputConversions;
begin
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(Boolean), TypeInfo(String));
TValueRefConverterFactory.RegisterConversion(TypeInfo(Boolean), TypeInfo(String),
TConverterDescription.Create(
procedure(const I: TValue; var O: TValue)
begin
if I.AsBoolean then
O := TValue.From<String>('-1')
else
O := TValue.From<String>('0');
end,
'BoolToString', 'BoolToString', EmptyStr, True, EmptyStr, nil)
);
end;
procedure UnregisterOutputConversions;
begin
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(Boolean), TypeInfo(String));
end;
Check out the full blog post about converting from an integer to a boolean using LiveBindings.
Mirror: Download a copy of the source code from the second integer to boolean LiveBindings sample.
Very help, thanks (obrigado)