Board index » delphi » Cant loop trhough database??

Cant loop trhough database??

Hi all,

I run a loop through my database, to look for a value. When the value is
found I need to change it to something else. The problem is when I do the
Edit-Change-Post routine, the loop exits and doesnt run any further. Can
anyone suggest anything?

Cheers    fuzzyd...@yahoo.com

  dmMain.tbCandidate.DisableControls;
  dmMain.tbCandidate.First;
  while not dmMain.tbCandidate.Eof do
    begin
      vRecordDate := dmMain.tbCandidate['LastUpdated'];
      if vLimit3Set = true then
        begin
          if ((Date - vRecordDate) >= vLimit3) AND
(dmMain.tbCandidate['CurrentStatus'] <> 2) then
            begin
              dmMain.tbCandidate.Edit;
              dmMain.tbCandidate['Status'] := 3;
              dmMain.tbCandidate['Mode'] := 4;
              dmMain.tbCandidate.Post;
            end;
        end;
      dmMain.tbCandidate.Next;
    end;
  dmMain.tbCandidate.EnableControls;

 

Re:Cant loop trhough database??


Depending on what controls you are using, you could bookmark your spot or
get the record number before you make the change.  After you make the
change, you can reset your cursor to the record number or bookmark again.

Quote
Doc <fuzzyd...@yahoo.com> wrote in message

news:7tiag3$mpf6@forums.borland.com...
Quote
> Hi all,

> I run a loop through my database, to look for a value. When the value is
> found I need to change it to something else. The problem is when I do the
> Edit-Change-Post routine, the loop exits and doesnt run any further. Can
> anyone suggest anything?

> Cheers    fuzzyd...@yahoo.com

>   dmMain.tbCandidate.DisableControls;
>   dmMain.tbCandidate.First;
>   while not dmMain.tbCandidate.Eof do
>     begin
>       vRecordDate := dmMain.tbCandidate['LastUpdated'];
>       if vLimit3Set = true then
>         begin
>           if ((Date - vRecordDate) >= vLimit3) AND
> (dmMain.tbCandidate['CurrentStatus'] <> 2) then
>             begin
>               dmMain.tbCandidate.Edit;
>               dmMain.tbCandidate['Status'] := 3;
>               dmMain.tbCandidate['Mode'] := 4;
>               dmMain.tbCandidate.Post;
>             end;
>         end;
>       dmMain.tbCandidate.Next;
>     end;
>   dmMain.tbCandidate.EnableControls;

Re:Cant loop trhough database??


Hi Doc

As Daaron says

When you change your Data, probably you force the record to be the last in
the active index, and then
your loop breaks.

Use Bookmarks before you change your Record

HTH
Antonio

Re:Cant loop trhough database??


Using SQL is much faster, if you can use SQL.

Be careful about Bookmarks. There is a bug. You have to close indexes
before setting and using Bookmarks.

Quote
Antnio Flix wrote in message <7tifv7$mp...@forums.borland.com>...
>Hi Doc

>As Daaron says

>When you change your Data, probably you force the record to be the
last in
>the active index, and then
>your loop breaks.

>Use Bookmarks before you change your Record

>HTH
>Antonio

Re:Cant loop trhough database??


Doc,

Also, don't call Table.Next after Table.Post - Post implicitly moves to the
next record.

Regards, Artur

Re:Cant loop trhough database??


When you want to edit records in table you must avoid using indices or
you can skip some.

Quote
Art wrote:
> Also, don't call Table.Next after Table.Post - Post implicitly moves to the
> next record.

Really? IMHO Table.Next implicitly calls Post.

Igor

Re:Cant loop trhough database??


Thanks for all the help. Problem is now solved :)

Other Threads