Board index » delphi » EOF always TRUE in a tframe's destructor

EOF always TRUE in a tframe's destructor

Hi all!. I have the following piece of code in a tframe's destructor:

destructor tFrame2.destroy;
begin
with query1 do
    begin
    sql.clear;
    sql.add('select * from MYTABLE');
    open;
    while not eof do
        begin
        // do something
        next;
        end;
    close;
    end;
inherited;
end;

Then EOF is always TRUE, even if MYTABLE has records!

I have verified that if I add a 'first' after the 'open' then things
work OK, but I don't know why this happens and would like to know if
someone else experiences same problems and/or solutions.

Thank you very much!

 

Re:EOF always TRUE in a tframe's destructor


Hello!

Quote
> Then EOF is always TRUE, even if MYTABLE has records!

> I have verified that if I add a 'first' after the 'open' then things
> work OK, but I don't know why this happens and would like to know if
> someone else experiences same problems and/or solutions.

As far as i remember it's not guaranteed that a cursor will point to first
record although it may be a bug of your sql client driver.

Good luck, Serge
--
http://www.cooldev.com/
#CoolControls, CoolMenus and more Cool VCL packs for Delphi development.
#KoolSockets, KoolStorage and other kernel level solutions.
#CdRwLib SDK, WNASPI SDK packages for CD manipulations.
#Offshore development of high quality.
CoolDev.Com

Re:EOF always TRUE in a tframe's destructor


"Serge Sapozhnikov" <s...@cooldev.com> escribi en el mensaje
news:3d005614_1@dnews...

Quote
> Hello!

> > Then EOF is always TRUE, even if MYTABLE has records!

> > I have verified that if I add a 'first' after the 'open' then things
> > work OK, but I don't know why this happens and would like to know if
> > someone else experiences same problems and/or solutions.

> As far as i remember it's not guaranteed that a cursor will point to first
> record although it may be a bug of your sql client driver.

> Good luck, Serge
> --
> http://www.cooldev.com/
> #CoolControls, CoolMenus and more Cool VCL packs for Delphi development.
> #KoolSockets, KoolStorage and other kernel level solutions.
> #CdRwLib SDK, WNASPI SDK packages for CD manipulations.
> #Offshore development of high quality.
> CoolDev.Com

Hummm... I'm not very sure... The same piece of code works in any other
event (p.e. in the constructor). Also, this is happening with Interbase and
Informix. And I never needed a 'first' after an 'open' (until now) .

Re:EOF always TRUE in a tframe's destructor


Is it possible that query1 is already open and at eof when the proc is
entered and, for some reason it's not automatically closing when you change
the sql?  IOW, try adding a query1.close.

Quote
"Pablo Len" <pablol...@eresmas.net> wrote in message

news:3cffe054_1@dnews...
Quote
> Hi all!. I have the following piece of code in a tframe's destructor:

> destructor tFrame2.destroy;
> begin
> with query1 do
>     begin
>     sql.clear;
>     sql.add('select * from MYTABLE');
>     open;
>     while not eof do
>         begin
>         // do something
>         next;
>         end;
>     close;
>     end;
> inherited;
> end;

> Then EOF is always TRUE, even if MYTABLE has records!

> I have verified that if I add a 'first' after the 'open' then things
> work OK, but I don't know why this happens and would like to know if
> someone else experiences same problems and/or solutions.

> Thank you very much!

Re:EOF always TRUE in a tframe's destructor


No. I have written a demo app having just these lines of code.

"Don Strenczewilk" <d...@nospamhammerlitho.com> escribi en el mensaje
news:3d0092f4_1@dnews...

Quote
> Is it possible that query1 is already open and at eof when the proc is
> entered and, for some reason it's not automatically closing when you
change
> the sql?  IOW, try adding a query1.close.

> "Pablo Len" <pablol...@eresmas.net> wrote in message
> news:3cffe054_1@dnews...
> > Hi all!. I have the following piece of code in a tframe's destructor:

> > destructor tFrame2.destroy;
> > begin
> > with query1 do
> >     begin
> >     sql.clear;
> >     sql.add('select * from MYTABLE');
> >     open;
> >     while not eof do
> >         begin
> >         // do something
> >         next;
> >         end;
> >     close;
> >     end;
> > inherited;
> > end;

> > Then EOF is always TRUE, even if MYTABLE has records!

> > I have verified that if I add a 'first' after the 'open' then things
> > work OK, but I don't know why this happens and would like to know if
> > someone else experiences same problems and/or solutions.

> > Thank you very much!

Re:EOF always TRUE in a tframe's destructor


Hi all!

I've found another work-around to the problem: If i override the new D6
BeforeDestruction method instaead the destroy destructor, then everything
works as espected, thoug i have no idea what was the problem!

"Pablo Len" <pablol...@eresmas.net> escribi en el mensaje
news:3cffe054_1@dnews...

Quote
> Hi all!. I have the following piece of code in a tframe's destructor:

> destructor tFrame2.destroy;
> begin
> with query1 do
>     begin
>     sql.clear;
>     sql.add('select * from MYTABLE');
>     open;
>     while not eof do
>         begin
>         // do something
>         next;
>         end;
>     close;
>     end;
> inherited;
> end;

> Then EOF is always TRUE, even if MYTABLE has records!

> I have verified that if I add a 'first' after the 'open' then things
> work OK, but I don't know why this happens and would like to know if
> someone else experiences same problems and/or solutions.

> Thank you very much!

Other Threads