Page 1 of 1

how to create calc field runtime by msquery

Posted: Wed 09 Dec 2009 08:08
by minair2004
hi
i need cod in create calc field runtime by msquery.

thnkx

Posted: Wed 09 Dec 2009 10:57
by Dimon
You can use the following code:

Code: Select all

var
  CalcField: TField;
begin
  CalcField := TIntegerField.Create(MSQuery);
  CalcField.Calculated := True;
  CalcField.FieldName := CalcFieldName;
  CalcField.DataSet := MSQuery;
end;

Posted: Wed 09 Dec 2009 13:10
by minair2004
thnx

i use this code. but msquery only show 1 fields. don't show another fields and error in exit form.

Posted: Wed 09 Dec 2009 15:31
by Dimon
To create the fields of your SQL query in run-time, use the following code:

Code: Select all

  MSQuery.FieldDefs.Update;
  for i := 0 to MSQuery.FieldDefList.Count - 1 do
    with MSQuery.FieldDefList[i] do
      if (DataType  ftUnknown) and not (DataType in ObjectFieldTypes) then
        CreateField(MSQuery, nil, MSQuery.FieldDefList.Strings[i]);
After that add calculated field and then open the query.