Subject | Re: [IBO] Is there an alternative to FieldByName? |
---|---|
Author | Geoff Worboys |
Post date | 2002-03-23T06:39:31Z |
> In the program I'm doing, I'm using the syntax:FieldByName one method of retrieving a field by name, but as you have
> IB_Query1.FieldByName('FIELDx').AsString to reference the FIELDx
> If you don't write correctly FIELDx, in compilation time seems it
> works good, but in execution time you get an error, or you don't get
> the good information.
> Is there any other way to do it?
observed you have to get it right. Thats why we test our programs :-)
See also the online help on the method TIB_Row.GetByName
eg.
if IB_Query1.Fields.GetByName( 'FieldX', tmpCol ) then
I know that some people use global variables or constants that define
the field number of a particular field so that they dont have to use
FieldByName at all. I am not a fan of this approach but it works
provided you remember to maintain the variable/constant according to
changes in your SQL.
IB_Query1.Fields[ FieldX_Number ].AsString := 'x'
A number of things can assist with program performance and readability
in regard to column references...
1. Do not use FieldByName inside a loop.
eg. for i := 0 to 100 do
IB_Query1.FieldByName( 'X').AsInteger := i;
is BAD - because the search/match of field names must be done on
every loop.
instead use something like...
procedure ...
var
XCol: TIB_Column;
begin
XCol := IB_Query1.FieldByName( 'X' );
for i := 0 to 100 do
XCol.AsInteger := i;
end;
(I know its a silly example but you should get the idea.)
Remember that a reference to a IBO column is only valid while the
dataset is prepared. If the dataset is unprepared and then prepared
again any old references will be invalid.
I think there is probably more about this in the FAQ on the website
and various tutorial applications.
--
Geoff Worboys
Telesis Computing