Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiDemoFiremonkeyIOSOSXWindows

LiveBindings Convert Integer Field To Boolean With Delphi XE5 Firemonkey On Android And IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE6 Firemonkey LiveBindings Integer To Boolean | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSMalcolm 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;
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(Boolean), TypeInfo(String));
TValueRefConverterFactory.RegisterConversion(TypeInfo(Boolean), TypeInfo(String),
procedure(const I: TValue; var O: TValue)
if I.AsBoolean then
O := TValue.From<String>('-1')
O := TValue.From<String>('0');
'BoolToString', 'BoolToString', EmptyStr, True, EmptyStr, nil)

procedure UnregisterOutputConversions;
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(Boolean), TypeInfo(String));

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.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging


Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

1 Comment

Leave a Reply