Subject | Re: [IBO] Calculated Fields - still didn´t go t them |
---|---|
Author | Lucas Franzen |
Post date | 2012-09-27T13:37:30Z |
Andrei,
Am 26.09.2012 16:28, schrieb Andrei Luís:
You can change it to sth. like:
3 if (AField.FieldName='MYCALC1') then
4 begin
5 AField.AsCurrency := ARow.ByName('FIELD_A').AsCurrency -
ARow.ByName('FIELD_B').asCurrency;
6 end // remove ";"
7
8 else if (AField.FieldName='MYCALC2') then // add ELSE!
since it's pretty useless to ask for field MYCALC2 when it was already
MYCALC1.
In the one above?
since it's not testing for aRow being assigned.
Am 26.09.2012 16:28, schrieb Andrei Luís:
> Hello folks,Yes, this is the code as it is used by IBO.
>
> I'm dealing with a performance problem for a long time, and I know that
> part of it has been the calculated fields I'm using.
>
> I'm doing them by 'my way', and by this I mean 'any way', not the best.
>
> I'm searching about this topic here in the list, and I found something like
> that:
>
> 1 procedure Tdm.qrTestCalculateField(Sender: TIB_Statement; ARow: TIB_Row;
> AField: TIB_Column);
> 2 begin
> 3 if (AField.FieldName='MYCALC1') then
> 4 begin
> 5 AField.AsCurrency := ARow.ByName('FIELD_A').AsCurrency -
> ARow.ByName('FIELD_B').asCurrency;
> 6 end;
> 7
> 8 if (AField.FieldName='MYCALC2') then
> 9 begin
> 10 AField.AsCurrency := ARow.ByName('FIELD_A').AsCurrency +
> ARow.ByName('FIELD_B').asCurrency;
> 11 end;
> 12
> 13 if (AField.FieldName='MYCALC3') then
> 14 begin
> 15 AField.AsCurrency := ARow.ByName('FIELD_A').AsCurrency *
> ARow.ByName('FIELD_B').asCurrency;
> 16 end;
> 17 end;
You can change it to sth. like:
3 if (AField.FieldName='MYCALC1') then
4 begin
5 AField.AsCurrency := ARow.ByName('FIELD_A').AsCurrency -
ARow.ByName('FIELD_B').asCurrency;
6 end // remove ";"
7
8 else if (AField.FieldName='MYCALC2') then // add ELSE!
since it's pretty useless to ask for field MYCALC2 when it was already
MYCALC1.
>With calculated fields I don't know neither another nor a faster way.
>
> My questions:
> 1 - Is this the best way to use calculated fields in IBO? I mean, is it the
> fastest way thinking about performance?
> 2 - I tried this code, but AField is always NIL!??? So if I run it likeIn which code AField was NIL?
> that, I get an access violation exception at line 3. So I tried to isolate
> this with a 'If AField = nil then exit', but every time the event is
> called, AField is nil, then nothing is calculated.
In the one above?
> 3 - How about the code below? This is what I'm doing today:This one should rather produce access violations than the one above
since it's not testing for aRow being assigned.
> 1 procedure Tdm.qrTestCalculateField(Sender: TIB_Statement; ARow:Luc.
> TIB_Row; AField: TIB_Column);
> 2 begin
> 3 ARow.ByName('MYCALC1').asCurrency :=
> ARow.ByName('FIELD_A').AsCurrency - ARow.ByName('FIELD_B').asCurrency;
> 4 ARow.ByName('MYCALC1').asCurrency :=
> ARow.ByName('FIELD_A').AsCurrency + ARow.ByName('FIELD_B').asCurrency;
> 5 ARow.ByName('MYCALC1').asCurrency :=
> ARow.ByName('FIELD_A').AsCurrency * ARow.ByName('FIELD_B').asCurrency;
> 6 end;