You can add calculated TField descendents to the Field list at run-time.

Your just need to call <Query>.Fields.Update and <Query>.CreateFields.

Just watch out, CreateFields is a TDataSet method and is not available
from TQuery so you need a Casting Cheat type.

--
type
        TCheatDataSet = class(TDataSet);
...
procedure CreateCalculatedStringField(PFieldName: String; PQuery:
TwwQuery; PSize: Integer);
var
  LCalculatedStringField: TStringField;
begin
  //Create also some calculated fields
  LCalculatedStringField := TStringField.Create(pQuery);
  LCalculatedStringField.FieldName := PFieldName;
  LCalculatedStringField.FieldKind := fkCalculated;
  LCalculatedStringField.Calculated := True;
  LCalculatedStringField.Size := PSize;
  LcalculatedStringField.DataSet := pquery;
end;
...
        <Query>.FieldDefs.Update;
        TCheatDataSet(<Query>).CreateFields;

// And now use CreateCalculatedStringField to add calculated string
fields.

TTFN.
----
Struan Judd     <*>             EMail:          [EMAIL PROTECTED]
CJN Technologies Ltd            Phone:          +64 (9) 415 4796
All opinions mine only  Mobile: +64 (21) 685 335

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, 22 January 1999 00:10
To: Multiple recipients of list delphi
Subject: [DUG]: Creating Fields at RunTime


How can I create a calculated field at runtime ?  Using FieldDefs.Add 
puts the field in fieldefs, but no where else.  It is missing from 
Fields property , the grid cant display it etc..
Rohit

======================================================================
CFL - Computer Fanatics Ltd.  21 Barry's Point Road, AKL, New Zealand
PH    (649) 489-2280 
FX    (649) 489-2290
email [EMAIL PROTECTED]  or  [EMAIL PROTECTED]
======================================================================
------------------------------------------------------------------------
---
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to