Subject RE: [IBO] TIBOQuery - where to create dynamic TFields?
Author Roger Vellacott
A much better way is to add calculated fields to the TIBOQuery
component. You can do this on the component, or in code.

//Somewhere in the initialisation code, or in form create.
with MyQuery.InternalDataset, CalculatedFields do
begin
Clear;
Add('CALC_FIELD_1 VARCHAR(20)');
Add(CALC_FIELD_2 DECIMAL(18,4)');
OnCalculateField := MyQueryCalculateField;
end;

procedure TMyForm.MyQueryCalculateField((Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
if AField.FieldName = 'CALC_FIELD_1' then
begin
AField.Value := ARow..ByName('FIELD_1').Value *
ARow.ByName('FIELD_2').Value;
end
else if AField.FieldName = 'CALC_FIELD_2' then
begin
//some other calculation
end;
end;

When referring to the current table (MyQuery) be careful to use ARow.
The values of fields in MyQuery may not have been updated to the
current record when the calculation takes place.

Roger Vellacott


-----Original Message-----
From: G. Nau [mailto:b404_r66@...]
Sent: 10 June 2007 20:26
To: iBObjects@yahoogroups.com
Subject: [IBO] TIBOQuery - where to create dynamic TFields?



I'm using IBO 4.7/FB2.0 with FastReport 4.1x and IBOs TDataset
compatible components.
It's working fine, but for some reasons I can not use the
TDataset-fieldeditor
to define additional calculated field.
I'd like to create dynamic tfields for the TIBOQuery using this code
fragment:

Procedure TLagerDrucken.Addfields;
VAR vkbrutto: tcurrencyfield;
begin
inherited;
vkbrutto:=TCurrencyField.Create(IBOQuery_Main);
with vkbrutto do
Begin
FieldKind:=fkCalculated;
fieldname:='vkbrutto';
calculated:=True;
DataSet:=IBOQuery_Main;
end;

But which event do I have to use to add these fields?

The only event Fastreport is triggering going into the report designer
is the
onprepare event. Adding my AddFields here is adding my field but then
I'm
missing all the default fields.
That's of course TDataset default behaviour:
-leave the Fieldeditor empty and TDataset is creating all fields from
the
query automatically
-want to use additional fields? Then use the field editor, but in this
case
you'll have to add ALL field to the query, too. That's bad, when the
query
itself is dynamic.

Any idea to get ALL fields of the query AND add some calculated ones?

Regards
Gunther