Subject Re: [IBO] Re: Example of CalculateFields !
Author Jason Wharton
>> Hi, in my table I have a field DATE. How do the difference between the
>> current date and the field DATA using CalculateFields ?
> You need to declare the calculated field metadata on CalculetedFields
> property, like:
> So, on the OnCalcFields event, you can fill the value:
> IB_Query1.FieldByName('DAYS').AsInteger :=
> DaysBetween(IB_Query1.FieldByName('MY_DATE').AsDate, Date);
> Don't try just copy and paste this code. This is a tip.

Rather than do FieldByName() in a calculate fields function you should use
the TIB_Row that is passed into the event. It is possible that calculated
fields may need to be derived for records other than the current row.

This is how it will likely appear:

AIB_Row.ByName('DAYS').AsInteger :=
DaysBetween(AIB_Row.ByName('MY_DATE').AsDate, Date);

This way you are working directly with the context being passed into the
event instead of assuming it is the current record being dealt with. This
kind of assumption will cause problems in your application.

In the standard TDataset Borland did some things to make the row in question
appear as the current row but that required some messy stuff I didn't want
to have to deal with in the IBO native components so I have a separate
designation between what I call the CurrentFields (or just Fields) and the

Having this made it quite easy when writing the TDataset wrapper because it
was ready at all times to present its TFields as being aligned with the
current or the buffer fields. So, in some respects, TDataset is a nice
wrapper. If you are familiar with it then you may just want to use the
TIBOxxxx components too.

Hope this helps.

Jason Wharton