I have created fields in TVirtualtable in code.
There is a TFloatfield created and using TMyQuery gives a fieldproperty Editmask to change the displayview. mask ###.## for amount 100 gives 100.00.
TVirtualTable.fields[0].Editmask is compiling, but gives a runtime error.
How can I format the text of my field?
I'm using MyDAC 7.5.10
Format a field
Re: Format a field
Hello,
This problem is due to the fact that the fields are not created before the explicit opening of VirtualTable (VirtualTable.Open), when attempting to address to a non-existent field, an error occurs. To solve the problem, you should create these fields:
This problem is due to the fact that the fields are not created before the explicit opening of VirtualTable (VirtualTable.Open), when attempting to address to a non-existent field, an error occurs. To solve the problem, you should create these fields:
Code: Select all
MyQuery1.Open;
VirtualTable1.Assign(MyQuery1);
for i := 0 to VirtualTable1.FieldDefs.Count -1 do
VirtualTable1.FieldDefs.Items[i].CreateField(VirtualTable1);
VirtualTable1.Fields[0].EditMask := '###.##';
VirtualTable1.Open;
-
- Posts: 19
- Joined: Tue 15 May 2012 09:34
Re: Format a field
Thanks. It wil not create a runtime error.
But the format isn't changed.
(Virtualtable1.Fields[4] as TFloatField).DisplayFormat := '##0.00' is the trick
But the format isn't changed.
(Virtualtable1.Fields[4] as TFloatField).DisplayFormat := '##0.00' is the trick
Re: Format a field
Hello,
The EditMask property is responsible not for display format, but for input format. To modify display format, the DisplayFormat property should be used ether bringing the field to a correspondent type (as in your example), or creating a variable of this type, for example:
The EditMask property is responsible not for display format, but for input format. To modify display format, the DisplayFormat property should be used ether bringing the field to a correspondent type (as in your example), or creating a variable of this type, for example:
Code: Select all
VirtualTable1Sal := TFloatField.Create(VirtualTable1);
VirtualTable1Sal.Name := 'sal';
VirtualTable1Sal.FieldName := 'sal';
VirtualTable1Sal.DisplayFormat := '####.##';
VirtualTable1Sal.DataSet := VirtualTable1;
VirtualTable1.Open;