Using Format in a livebindings CustomFormat

Mike Sutton picture Mike Sutton · Sep 14, 2013 · Viewed 7.5k times · Source

I'm trying to use LiveBindings to format a number for display in a TEdit on a FireMonkey form.

I'm trying to use the Format method in the CustomFormat of the binding to format the number with two decimal places.

I can 'hard code' the output:

Format("Hello", %s)

which is working, but I can't work out what formatting string to use. If I try a standard formatting string such as,

Format("%.2f", %s)

I get a runtime error "Format invalid or incompatible with argument".

Indeed I get an error whenever I include a % symbol in the format string, so I'm guessing Format takes a different type of argument, but I can't find any documentation to say what the correct format string is.

Answer

moskito-x picture moskito-x · Sep 16, 2013

You can not use Format('%.2f',[%s]) in LiveBindings -> CustomFormat

The %s is reserved for the data and for a TEdit , it's a string

d : double;
s : string;
...
d := 1234.5678;
s:=Format('%.2f',[d]);

Format() is to convert [int, decimal, double, float] to a string .
all other give you a error : invalid argument
valid is for example

TLinkControlToField1 -> CustomFormat : "Double : "+UpperCase(%s)

will give you in Edit1.text

Double : 1234.5678

OK , we know that Uppercase() for '1234.5678' has no effects .
Is only to show (%s) is a string

Solutions:


enter image description here