2010. szeptember 18., szombat

How to add a calculated field to a dynamically created TTable


Problem/Question/Abstract:

How to add a calculated field to a dynamically created TTable

Answer:

var
  f: TField;
  i: Integer;
begin
  table1.FieldDefs.Update
    Table1.Close;
  for i := 0 to Table1.FieldDefs.Count - 1 do
    {create persistent field that does not exist}
    if table1.FindField(table1.FieldDefs[i].Name) = nil then
      table1.FieldDefs.Items[i].CreateField(Table1);
  {create a calculated field}
  f := TStringField.Create(Table1);
  f.Name := 'Table1CalcField';
  f.FieldName := 'CalcField';
  f.DisplayLabel := 'CalcField';
  f.Calculated := True;
  f.DataSet := Table1;
  Table1.Open;
end;

Nincsenek megjegyzések:

Megjegyzés küldése