Board index » delphi » Adding a Calculated field dynamically...

Adding a Calculated field dynamically...

Hello, dear friends...
I'm trying to add dynamically a calculated field to a TTable object and it
don't work !!!
I have a class TMyTable = Class (TTable) which I open dynamically.I want to
add a Calculated StringField to this table by program...
Thanks a lot in advance.
Pierre.
Sorry for my very bad english !!!

 

Re:Adding a Calculated field dynamically...


Quote
>I'm trying to add dynamically a calculated field to a TTable object and it
>don't work !!!
>I have a class TMyTable = Class (TTable) which I open dynamically.I want to
>add a Calculated StringField to this table by program...

here is an example but don't forget you still need to handle the
calcualted field in your tables onCalcFields event.

 Table1.Active:=false; // Must be false to add Fields to the Dataset
  Table1.FieldDefs.Update; // Make sure we have the latest Fields

  Monthly:=TFloatField.Create(Table1);
  Monthly.FieldName:='Monthly Salary';
  Monthly.Calculated:=true;
  Monthly.Dataset:=Table1;
  Monthly.DisplayFormat:='$#,0.00';

  Table1.Active:=true;

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Other Threads