The Text
property is meant to be used to obtain the textual representation of a field being edited in a DataAware control, in contrast with the DisplayText
property that gives you a string to represent the value to the user (it may contain punctuation or other decoration to the plain value).
Contains the string to display in a data-aware control when the field is in edit mode
A typical example is a TFloatField with the Currency
property set to True
. The DisplayText
gives you a string with the number containing commas (if needed), the decimal separator and a currency symbol. The Text
property gives you a string without commas or currency symbol.
begin
MyFloatField.Currency := True;
MyFloatField.AsFloat := 1234.56;
A := MyFloatField.Text; //'1234.56'
B := MyFloatField.DisplayText; //'$1,234.56', depends on your locale
end;
Both above properties can be customized writing a OnGetText
event handler where you can write custom logic to convert the value to a string representation. The DisplayText
parameter indicates if the wanted string is meant to represent the value for edit or not.
On the other hand, the AsString
property uses a more plain conversion between the base data type and string. Each TField descendant implements the virtual GetAsString method using functions from the RTL to perform that representation. Following the TFloatField example, this class calls FloatToStr()
for that purpose.
All this said, the answer to your question is: AsString
returns the same string as the Text
property if there's no OnGetText event handler, but it may be different if there's a event handler or a non-standard TField descendant.
I can't tell what is more appropriate for you, because it depends on what's the intended use for the returned value, but if you're using it to display the values to the user in the UI (as your code example), I advise you to use the DisplayText property.