Board index » delphi » Programatically adding calculated fields to TQuery??

Programatically adding calculated fields to TQuery??

Does anybody know how to do this?

Can it be done?

I've managed to add a calculated (sort of) field before opening a query,
but then the field I added is the only field in the Dataset after its
opened. (?)

Using the TField.OnGetText event to calculate a new value for an
existing field does the job when the Query results are displayed in
DataAware controls, but the Reporting tool (Piparti)  we're using never
sets off OnGetText when displaying a report.

Tim.

 

Re:Programatically adding calculated fields to TQuery??


What are yout trying to accomplish?  There may be an easier way.  If you are
creating the calculated field on the fly how are you going to create the
OnCalcFields event handler?  You cannot do that at run time.

--
Bill

(TeamB cannot answer questions received via email.)
(To contact me for any other reason remove nospam from my address)

Re:Programatically adding calculated fields to TQuery??


Quote
>Does anybody know how to do this?

>Can it be done?

>I've managed to add a calculated (sort of) field before opening a query,
>but then the field I added is the only field in the Dataset after its
>opened. (?)

Yes you can add calculated fields from code.

here is some sample code

  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