Board index » delphi » TDataset Next vs FindNext

TDataset Next vs FindNext

Hi everyone [[[[[[':-)

Compare those 2 loops iterating a dataset :

1)
    aDataset.First
    while not aDataset.Eof do begin
        ...
        aDataset.Next;
        end;
2)
    if not aDataset.FindFirst then repeat
        ...
        until not aDataset.FindNext;

I think that the first loop has one disadvantage: in case that a range is
already set for the dataset (or is a detail to a master one) it will iterate
at least once since the Eof function will not be set to true after calling
"First" method. To avoid this a RecordCount check should be added in the
"while" condition.

I personally prefer to use the second loop even if it's possible to be
slower.

Any opinions or againsts to this?

 

Re:TDataset Next vs FindNext


If it slows down, I am against it, as I think that adding some additional
code, but have a good performance is more importantly. To me and my
customers.

regards,

Kees.

netrino <netr...@iname.com> schreef in berichtnieuws
8ck4e5$8...@bornews.borland.com...

Quote
> Hi everyone [[[[[[':-)

> Compare those 2 loops iterating a dataset :

> 1)
>     aDataset.First
>     while not aDataset.Eof do begin
>         ...
>         aDataset.Next;
>         end;
> 2)
>     if not aDataset.FindFirst then repeat
>         ...
>         until not aDataset.FindNext;

> I think that the first loop has one disadvantage: in case that a range is
> already set for the dataset (or is a detail to a master one) it will
iterate
> at least once since the Eof function will not be set to true after calling
> "First" method. To avoid this a RecordCount check should be added in the
> "while" condition.

> I personally prefer to use the second loop even if it's possible to be
> slower.

> Any opinions or againsts to this?

Re:TDataset Next vs FindNext


On Fri, 7 Apr 2000 11:06:51 +0300, "netrino" <netr...@iname.com>
wrote:

Quote
>I think that the first loop has one disadvantage: in case that a range is
>already set for the dataset (or is a detail to a master one) it will iterate
>at least once since the Eof function will not be set to true after calling
>"First" method. To avoid this a RecordCount check should be added in the
>"while" condition.

If your EOF flag is not set after setting the range, there is
something wrong with your table.  RecordCount has to be avoided in all
cases, imho.  It can be slow and give unreliable results for some
databases.

Jan

Re:TDataset Next vs FindNext


I must be missing a few things here.  First, why would one choose FindFirst
over FindKey or GotoKey and why would one need either if SetRange is in
effect?  In the same vein, why FindNext rather than just Next?  Finally, why
methods of TDataSet rather than TTable?

Inquiring minds....

Paul / ColumbuSoft
www.columbusoft.com

Quote
Jan Sprengers <j...@nospamplease.adm2000.be> wrote in message

news:38ede75a.350184678@forums.inprise.com...
Quote
> On Fri, 7 Apr 2000 11:06:51 +0300, "netrino" <netr...@iname.com>
> wrote:

> >I think that the first loop has one disadvantage: in case that a range is
> >already set for the dataset (or is a detail to a master one) it will
iterate
> >at least once since the Eof function will not be set to true after
calling
> >"First" method. To avoid this a RecordCount check should be added in the
> >"while" condition.

> If your EOF flag is not set after setting the range, there is
> something wrong with your table.  RecordCount has to be avoided in all
> cases, imho.  It can be slow and give unreliable results for some
> databases.

> Jan

Re:TDataset Next vs FindNext


On Sat, 8 Apr 2000 01:10:41 -0400, "Paul Ferrara"

Quote
<p...@nospam.columbusoft.com> wrote:
>I must be missing a few things here.  First, why would one choose FindFirst
>over FindKey or GotoKey and why would one need either if SetRange is in
>effect?  In the same vein, why FindNext rather than just Next?

I think that he wants to use either a range or the FindXxxx methods.

Quote
>Finally, why methods of TDataSet rather than TTable?

He is using a TTable more than likely, so why would it matter on what
level the methods are declared?

Jan

Re:TDataset Next vs FindNext


If a range or filter is in effect, all that's necessary is to issue First,
correct?  As I read the help file, Borland seems to be saying that you
should use the methods of the descendents rather than those of TDataSet
itself, which is why I asked.

Paul / ColumbuSoft
www.columbusoft.com

Quote
Jan Sprengers <j...@nospamplease.adm2000.be> wrote in message

news:38eef4a3.419121795@forums.inprise.com...
Quote
> On Sat, 8 Apr 2000 01:10:41 -0400, "Paul Ferrara"
> <p...@nospam.columbusoft.com> wrote:

> >I must be missing a few things here.  First, why would one choose
FindFirst
> >over FindKey or GotoKey and why would one need either if SetRange is in
> >effect?  In the same vein, why FindNext rather than just Next?

> I think that he wants to use either a range or the FindXxxx methods.

> >Finally, why methods of TDataSet rather than TTable?

> He is using a TTable more than likely, so why would it matter on what
> level the methods are declared?

> Jan

Re:TDataset Next vs FindNext


On Sat, 8 Apr 2000 05:37:35 -0400, "Paul Ferrara"

Quote
<p...@nospam.columbusoft.com> wrote:
>If a range or filter is in effect, all that's necessary is to issue First,
>correct?

Correct and agreed.  A range is the fastest and easiest method.

Quote
>As I read the help file, Borland seems to be saying that you
>should use the methods of the descendents rather than those of TDataSet
>itself, which is why I asked.

Right.  But these methods are all virtual at the TDataSet level, so
you would be using the descendant-specific code anyhow; even in an
event handler that takes a TDataSet as a parameter, like OnCalcFields.

But I have to admit that the help file is sometimes confusing.  If you
look at the help for GotoBookmark, it looks like it is written for the
authors of a TDataSet descendant, not for the average TTable or TQuery
user.

Jan

Re:TDataset Next vs FindNext


Hello Jan,

Quote
>If your EOF flag is not set after setting the range, there is
>something wrong with your table.

 My EOF flag is not set because the range is set automatically by a master
detail relationship

Quote
>RecordCount has to be avoided in all
>cases, imho.  It can be slow and give unreliable results for some
>databases. I agree - RecordCound is not a good solution

Regards

Re:TDataset Next vs FindNext


Hello Paul,

Quote
> First, why would one choose FindFirst over FindKey or GotoKey and why

would one need either if SetRange is in effect?
FindFirst is actually a more powerfull First method (respects filtering) -
has nothing to do with FindKey

Quote
>Finally, why methods of TDataSet rather than TTable?

Actually I'm using TDataset descendants in my programs. I'm refering to
TDataset only because It's the parent  of the familly and the question is a
rather generic.

Regards

Re:TDataset Next vs FindNext


If a range is set, no matter how it gets set, 'while not EOF' is all you
need.  When 'next' is issued while on the last record in the range, EOF will
be True.

Paul / ColumbuSoft
www.columbusoft.com

Quote
netrino <netr...@iname.com> wrote in message

news:8cum3j$fcd7@bornews.borland.com...
Quote
> Hello Jan,

> >If your EOF flag is not set after setting the range, there is
> >something wrong with your table.
>  My EOF flag is not set because the range is set automatically by a master
> detail relationship

> >RecordCount has to be avoided in all
> >cases, imho.  It can be slow and give unreliable results for some
> >databases. I agree - RecordCound is not a good solution

> Regards

Re:TDataset Next vs FindNext


I think my point was, and was confirmed by Jan, that if you have a range or
filter in effect, you don't need Findanything.  First, Next, while not EOF,
etc will do it.

Paul / ColumbuSoft
www.columbusoft.com

Quote
netrino <netr...@iname.com> wrote in message

news:8cum3l$fcd8@bornews.borland.com...
Quote
> Hello Paul,

> > First, why would one choose FindFirst over FindKey or GotoKey and why
> would one need either if SetRange is in effect?
> FindFirst is actually a more powerfull First method (respects filtering) -
> has nothing to do with FindKey

> >Finally, why methods of TDataSet rather than TTable?
> Actually I'm using TDataset descendants in my programs. I'm refering to
> TDataset only because It's the parent  of the familly and the question is
a
> rather generic.

> Regards

Other Threads