delphidisplayformat

Table (or CDS) Field DisplayFormat


When adding persistent fields of a dataset using the Fields Editor, the field names are concatenated to the dataset as TableMyField, I can then access the persistent field's DisplayFormat property in my code as:

TableMyField.DisplayFormat

However, if I don't use the Fields Editor and don't use persistent fields, how can I access the DisplayFormat property at run time?


Solution

  • Since the DisplayFormat property is contained in descending classes of TField, you'd need to cast at runtime. You can do this a couple of different ways.

    TNumericField(Dataset.Fieldbyname('CostPrice')).DisplayFormat := '#,###.00';
    
    (Dataset.fieldbyname('CostPrice') as TNumericField).DisplayFormat := '#,###.00';
    
    TNumericField(Dataset.fields[0]).DisplayFormat := '#,###.00';