Subject | RE: [IBO] TIBOQuery - where to create dynamic TFields? |
---|---|
Author | G. Nau |
Post date | 2007-06-11T06:33:48Z |
Roger, thanks for the reply.
But I'm using TDataset compatible TIBOQuery, not the native IBO ones, for
fast report.
So the definition of the calculated fields is different but already working:
procedure TLagerDrucken.IBOQuery_MainCalcFields(DataSet: TDataSet);
begin
inherited;
With IBOQuery_Main do
Begin
fieldbyname('VKBRUTTO').AsCurrency:=CalculateBrutto(fieldbyname('vkpre
is').Ascurrency,Fieldbyname('mwstnr').AsInteger);
End;
end;
My problem is creating at least ONE calculated Tfield in the query and I'm
lossing ALL the default fields of the query. That's default TDataset behaviour
and not IBO specific.
I need the default fields for the query auto-generated. The SQL of the query
is dynamic, so I can't define the fields statically.
Then I have to add some calculated tfields. And that's the point where I'm
stuck at the moment and need some help.
Am 10 Jun 2007 um 21:48 hat Roger Vellacott geschrieben:
But I'm using TDataset compatible TIBOQuery, not the native IBO ones, for
fast report.
So the definition of the calculated fields is different but already working:
procedure TLagerDrucken.IBOQuery_MainCalcFields(DataSet: TDataSet);
begin
inherited;
With IBOQuery_Main do
Begin
fieldbyname('VKBRUTTO').AsCurrency:=CalculateBrutto(fieldbyname('vkpre
is').Ascurrency,Fieldbyname('mwstnr').AsInteger);
End;
end;
My problem is creating at least ONE calculated Tfield in the query and I'm
lossing ALL the default fields of the query. That's default TDataset behaviour
and not IBO specific.
I need the default fields for the query auto-generated. The SQL of the query
is dynamic, so I can't define the fields statically.
Then I have to add some calculated tfields. And that's the point where I'm
stuck at the moment and need some help.
Am 10 Jun 2007 um 21:48 hat Roger Vellacott geschrieben:
> 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
>
>
>
>
>
>
> ___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> without the need for BDE, ODBC or any other layer.
> ___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info papers,
> keyword-searchable FAQ, community code contributions and more !
> Yahoo! Groups Links
>
>
>