BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Posting edits to last record of a filtered table causes EOF

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.databases
View previous topic :: View next topic  
Author Message
Kris Leech
Guest





PostPosted: Wed Jan 28, 2004 5:17 pm    Post subject: Posting edits to last record of a filtered table causes EOF Reply with quote



I have this semi-pseudo code:

Table.Filter := 'Status = 0';
Table.Filtered := True;

While not Table.eof do
begin
Table.Edit;
Table.FieldByName('Status').AsInteger := 1;
Table.Post;
// Table.Next; Not required since as soon as Status field changed it
is not included in filtered results.
end;


This works fine until the last record. When post is called for the
last record a EOF exception is raised. Why? At the time of posting
there is a record to post to, I can see it in a data grid. Once the
record has been posted there are then no records left and the loop is
over.

Any suggestions, I cant seem to find anything about this problem.

Cheers Kris.
Back to top
Dan
Guest





PostPosted: Wed Jan 28, 2004 7:19 pm    Post subject: Re: Posting edits to last record of a filtered table causes Reply with quote



On 28 Jan 2004 09:17:19 -0800, [email]krisleech (AT) email (DOT) com[/email] (Kris Leech) wrote:

Quote:
I have this semi-pseudo code:

Table.Filter := 'Status = 0';
Table.Filtered := True;

While not Table.eof do
begin
Table.Edit;
Table.FieldByName('Status').AsInteger := 1;
Table.Post;
// Table.Next; Not required since as soon as Status field changed it
is not included in filtered results.
end;


This works fine until the last record. When post is called for the
last record a EOF exception is raised. Why? At the time of posting
there is a record to post to, I can see it in a data grid. Once the
record has been posted there are then no records left and the loop is
over.

Any suggestions, I cant seem to find anything about this problem.

Cheers Kris.
Several ways come to mind:

1. Use a query to update the table
UPDATE tablename
SET status = 1
WHERE status = 0

2. Your code is failing because when you get to the last record, you
*are* at the end of file.
Try these:
while not table.IsEmpty do
status := 1;

while not (table.eof and table. bof) do ...

The problem with these two and your method is that there is a
possibility of some error causing an infinite loop, where the while
condition is never met.

3. Using CachedUpdates true for the TTable may also avoid the problem,
since you won't post the new value for status while you iterate
through the dataset. Haven't tried it, but it might work for you.

HTH,
Dan

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.