Subject Re: [IBO] Accessing data object fields
Author Helen Borrie
At 08:24 AM 24/06/2003 +0200, you wrote:
>Hi,
>
>How do I access the fields of a IB_Query (or other data object)? With other
>components, I would write
>
>MYQuery.FieldByName('MyField').AsInteger
>
>for example. Also, how do I access the properties of the fields? How do I say
>
>case MYQuery.FieldByName('MyField').DataType of
>
>using IBObjects?

Look up the help for TIB_Column, and all will be revealed. I suspect that
what you want is the SQLType property.

Native IBO doesn't create persisent TField objects as the TDataset
architecture does. What it does is to put the entire row structure of the
output set into a collection of TIB_Column objects called a TIB_Row. You
fill in the stuff that *you* know about (and want IBO to know about) for
each column and IBO does the rest at Prepare time. So, you can't test an
unknown output field's data type unless the set is prepared - IOW, you
should READ SQLType, but not try to write to it. A TIB_Column's Value
property is a variant (except blobs) and native IBO has many more
AsWhatever methods than the VCL to cast data when reading it or writing to it.

To access a TIB_Column, you have several options:

FieldByName, pretty much like the VCL

Fields[n] to access a column by its absolute, zero-based array position -
will throw an exception on an unprepared statement. Fields is a TIB_Row

Fields['FieldName'] is the same as Fields[n] - it reads the row object's
FieldNames[] array to resolve the array index. It's a bit safer than
Fields[n] if you know the names of the columns, because IB and also
Firebird up to and incl. release 1.0.x have a bug on the returning column
order under some conditions.

You can also access a column via the TIB_Row itself, using the ByName
method of TIB_Row.

cheers,
Helen