Subject Re: [IBO] TIB_CheckBox delay
Author Geoff Worboys
> I've checked the value of one my TIB_Edits on the same form
> and it has the correct row's value when this event occurs
> (I read it via IB_Edit4->Field->AsString, is this OK?),

This is reading the value from the dataset. That is; it is going to
the control, getting the field/column reference and then reading the
AsString property from the field within the dataset. The code would
not be safe on its own, as the Field reference will not be valid
unless the dataset is prepared.

You could do the same thing for the Checkbox...
IB_CheckBox->Field->AsBoolean


> > My preference when in a data component is to use data
> > properties/methods.
>
> Can do! (You mean something like (ClientsQry->FieldByName
> ("ACCNTHLDR")->AsString == "T"), right?)

Yes, although if the field has been defined as boolean;
ColumnAttributes contains..
FieldName=BOOLEAN=T,F

then you can simply use
ClientsQry->FieldByName("ACCNTHLDR")->AsBoolean


> > If you are worried about the performance of using
> > FieldByName, you could setup column references in
> > OnPreparedChanged.
>
> I'm not sure what you're suggesting here.
> Can you elaborate please?

Firstly, the following description is only really worthwhile if the
event is going to be called many times in a tight loop. If it is just
an event for normal user interaction the FieldByName mechanism should
be adequate.

So for a tight loop situation it is better to get a column reference
before the loop starts so that you can use it within the loop without
having to go through the FieldByName searching for every run through
the loop. A normal situation would be where the initialisation and
loop all occurs in a single function such as...

TIB_Column *Col;
Col = MyQuery->FieldByName("MYFIELD");
for( i = 0; i < 100; i++ )
Col->AsInteger = i;

is much more efficient than...

for( i = 0; i < 100; i++ )
MyQuery->FieldByName("MYFIELD")->AsInteger = i;


However, if the body of the loop processing ends up in an event
handler, you dont get the chance of efficiently initialising a local
column reference. So what you can do is create a private data member
on the form

private:
TIB_Column *FTmpColumn;

In the OnPreparedChanged handler of the dataset initialise the column
reference according to whether the query is prepared or not (the
column only exists when the query is prepared)...

if ( MyQuery->Prepared )
FTmpColumn = MyQuery->FieldByName("MYFIELD");
else
FTmpColumn = 0;

Then in the main event handler you can...

if ( FTmpColumn )
DoSomethingWith( FTmpColumn.AsInteger );


HTH

Geoff Worboys
Telesis Computing