Subject Re: [IBO] TIB_Query.FieldByName().AsInterger -> Accessviolation
Author Paul Vinkenoog
Hi Rainer,

> I have a Query always doing the same select on the same table.
>
> In a loop :
> <MyQuery>.Refresh;
> with <MyQuery> do
> begin
> First;
> while not EOF do
> begin
> try
> r:=2+FieldByName('DESTINATION').AsInteger;
> except
> ....;
> end;
> ....
>
> I very often end in the exception because of a accessviolation :-(
> What am I doing wrong?

The Access Violation suggests that the fields aren't set up yet,
i.e. the query is unprepared. But the Refresh and the First seem to
work, so...

Maybe you could try this - it's better practice anyway:

{ before the loop, but after making sure the query is prepared: }

FieldDest : TIB_Column = MyQuery.FieldByName( 'DESTINATION' );

{ within the loop: }

r := 2 + FieldDest.AsInteger;

This is more efficient because otherwise the field has to be
found-by-name again and again, for every iteration of the loop.

Then step through your code in the debugger and see at what point it
goes wrong.

I know, this is not exactly the answer to you question but it might
help to hunt down the cause.


Greetings,
Paul Vinkenoog

PS:
Hope I got the Pascal syntax OK - it's been a while :-)