Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 10 of 10 total |
Filter and end of range |
Sat, Sep 24 2011 11:48 PM | Permanent Link |
Gerald J. Clancy, Jr. | D5 Ent.
I have a filter set on a specific date. I go to the first record in the set and process the records. However, I never detect when I am beyon the filter date. Here is a snippet of the code: while (not DM.aptVotes.EOF) do begin sBill := DM.aptVotes.FieldByName('BILL').AsString; ....do things that change the vote record pointer... DM.aptVotes.IndexName := 'bill'; DM.aptVotes.FindKey([sBill]); while (not DM.aptVotes.EOF) and (not DM.aptVotes.Last) and (DM.aptVotes.FieldByName('BILL').AsString = sBill) do DM.aptVotes.Next; end; The end of file is never set. the Next line stays on the last record of the set and never triggers EOF or exits the "while".. What don't I know? Jerry |
Sat, Sep 24 2011 11:55 PM | Permanent Link |
Gerald J. Clancy, Jr. | Correction: I copied the wrong "while" statement (the one below is invalid).
Here is what I am using: while (not DM.aptVotes.EOF) and (DM.aptVotes.FieldByName('BILL').AsString = sBill) do DM.aptVotes.Next; Jerry "Jerry Clancy" <jclancy@billtrak.com> wrote in message news:4DC687F9-B226-4BDC-A5EE-E52AF0570DEF@news.elevatesoft.com... > D5 Ent. > > I have a filter set on a specific date. I go to the first record in the > set and process the records. However, I never detect when I am beyon the > filter date. Here is a snippet of the code: > > while (not DM.aptVotes.EOF) do begin > sBill := DM.aptVotes.FieldByName('BILL').AsString; > > ....do things that change the vote record pointer... > > DM.aptVotes.IndexName := 'bill'; > DM.aptVotes.FindKey([sBill]); > while (not DM.aptVotes.EOF) and (not DM.aptVotes.Last) and > (DM.aptVotes.FieldByName('BILL').AsString = sBill) > do DM.aptVotes.Next; > end; > > The end of file is never set. the Next line stays on the last record of > the set and never triggers EOF or exits the "while".. > > What don't I know? > > Jerry > |
Sun, Sep 25 2011 5:12 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Jerry
The EoF test specifically relies on the cursor being moved past th last record and you tell it not to. Try changing while (not DM.aptVotes.EOF) and (DM.aptVotes.FieldByName('BILL').AsString = sBill) do DM.aptVotes.Next; to while (DM.aptVotes.FieldByName('BILL').AsString = sBill) do DM.aptVotes.Next; I'm not sure it will work because if the condition (DM.aptVotes.FieldByName('BILL').AsString = sBill) doesn't occur you're just going to wizz round the outer loop forever. These sort of loops are always tricky and have tripped me up more than once. If you have a filter set then change the filter condition and post the record and the record vanishes from the set you're working on and moves to the next record. No need for a next. If you don't change something and the record stays in the set you need a next. If you can't figure it out post the entire piece of code and I'll see if I can help. Roy Lambert [Team Elevate] |
Sun, Sep 25 2011 1:34 PM | Permanent Link |
Gerald J. Clancy, Jr. | Roy,
Thanks for the shot but no banana. With your suggestion it continually loops on the last valid record, never setting EOF, as it did with my initial code. Here's the code that I got to work: nVRecNo := DM.aptVotes.RecNo; while ...some condition...do begin DM.aptVotes.IndexName := 'votedate'; { Already set, though same index - 10-23-08 } DM.aptVotes.RecNo := nVRecNo; if (DM.aptVotes.FieldByName('BILL').AsString = sBill) then begin while (DM.aptVotes.FieldByName('BILL').AsString = sBill) do begin DM.aptVotes.Next; if DM.aptVotes.EOF then Break else ; Application.ProcessMessages; { REMOVE THIS EVIL COMMAND LATER } end; end else ; if DM.aptVotes.EOF then Break else ; sBill := DM.aptVotes.FieldByName('BILL').AsString; nVRecNo := DM.aptVotes.RecNo; end; {while} Added the ProcessMessages so I could stop the endless looping. I also tested that sBill is the current bill before skipping records. I don't understand why, if this works, my original line doesn't: while (not DM.aptVotes.EOF) and (DM.aptVotes.FieldByName('BILL').AsString = sBill) do begin .... Does not skipping beyond the filter range set EOF? Tim? Couldn't find much in the docs on this. Jerry "Roy Lambert" <roy@lybster.me.uk> wrote in message news:34D39F15-EFEC-4882-9D37-126195DA6D3B@news.elevatesoft.com... > Jerry > > > The EoF test specifically relies on the cursor being moved past th last > record and you tell it not to. > > Try changing > > while (not DM.aptVotes.EOF) and > (DM.aptVotes.FieldByName('BILL').AsString = sBill) > do DM.aptVotes.Next; > > to > > while (DM.aptVotes.FieldByName('BILL').AsString = sBill) do > DM.aptVotes.Next; > > I'm not sure it will work because if the condition > (DM.aptVotes.FieldByName('BILL').AsString = sBill) doesn't occur you're > just going to wizz round the outer loop forever. > > These sort of loops are always tricky and have tripped me up more than > once. If you have a filter set then change the filter condition and post > the record and the record vanishes from the set you're working on and > moves to the next record. No need for a next. If you don't change > something and the record stays in the set you need a next. > > If you can't figure it out post the entire piece of code and I'll see if I > can help. > > Roy Lambert [Team Elevate] > |
Mon, Sep 26 2011 5:40 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Jerry
>Thanks for the shot but no banana. With your suggestion it continually loops >on the last valid record, never setting EOF As I said it might. There's obviously a wadge of code missing or I'm definitely going senile because I can see no purpose or reason to the code you posted unless its simply this line nVRecNo := DM.aptVotes.RecNo; >I don't understand why, if this works, my original line doesn't: Are you sure it does work? From how I read the code it can exit wrongly quite easily leaving sBill and nVRecNo wrongly set. It is confusing code to read, and will also probably be quite inefficient. Can you post what it is you're trying to achieve and the table and index structures. Roy Lambert [Team Elevate] |
Mon, Oct 3 2011 9:47 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Jerry,
<< The end of file is never set. the Next line stays on the last record of the set and never triggers EOF or exits the "while".. >> My first reaction is that you must be wrong - if there was a general EOF issue with filtered datasets, then EDB would be in a world of hurt (as would I). What version of EDB are you using ? Can you send me an example of the problem as a small project ? Thanks, -- Tim Young Elevate Software www.elevatesoft.com |
Wed, Oct 12 2011 8:52 PM | Permanent Link |
Gerald J. Clancy, Jr. | Firstly, Roy, my apologies for the late response. I got wacked by about a
dozen things that weren't planned on. Got back to this today. Wrote a simpler test program to sort it out. The 'Bill' index on tblVotes has these fields: BILL;VOTEDATE;HOUSE;ACTION I used a listbox with a handful of bill ids in it to drive the program. There are two datepickers on the form (Start/End). Here is the code that works. with tblVotes do begin if not Active then Open else ; IndexName := 'bill'; { VOTEDATE is part of this index } Filtered := False; sDFilter := ''; Filter := ''; if not cbxAllVotes.Checked then begin { Use sDFilter so we can see the runtime result } sDFilter :='((VOTEDATE >= '+QuotedStr(AnsiDateToStr(dpStart.Date)) + ') ' + 'AND (VOTEDATE <= '+QuotedStr(AnsiDateToStr(dpEnd.Date)) + ') ' + ')'; Filter := sDFilter; Filtered := True; end else ; iFilteredCount := FilterRecordCount; iRecordCount := RecordCount; First; end; for i := 0 to lstBills.Items.Count - 1 do begin sBill := lstBills.Items[i]; if tblVotes.FindKey([sBill]) then begin sDate := tblVotes.FieldByName('VOTEDATE').AsString; while (not tblVotes.EOF) and (tblVotes.FieldByName('BILL').AsString = sBill) do begin Memo1.Lines.Add(sBill + ', ' + sDate); tblVotes.Next; end; end else Memo1.Lines.Add(sBill + ' not found for dates'); end; {for} tblVotes.Filtered := False; tblVotes.Filter := ''; tblVotes.Close; ShowMessage('Done'); except ShowMessage('Error encountered: ' + sBill + ', ' + sDate); end; My problem earlier seems to have been mixing two different database indexes incorrectly (there is another index on VOTEDATE;BILL). In the above code we never change the base index. The code is embedded in the most complex of all our units, which futher complicated clarity. Thank you for your efforts on my behalf. Jerry "Roy Lambert" <roy@lybster.me.uk> wrote in message news:A864217D-3CBF-4A5D-87DB-E84BD8DF27A4@news.elevatesoft.com... > Jerry > >>Thanks for the shot but no banana. With your suggestion it continually >>loops >>on the last valid record, never setting EOF > > > As I said it might. There's obviously a wadge of code missing or I'm > definitely going senile because I can see no purpose or reason to the code > you posted unless its simply this line > > nVRecNo := DM.aptVotes.RecNo; > >>I don't understand why, if this works, my original line doesn't: > > Are you sure it does work? From how I read the code it can exit wrongly > quite easily leaving sBill and nVRecNo wrongly set. It is confusing code > to read, and will also probably be quite inefficient. > > Can you post what it is you're trying to achieve and the table and index > structures. > > Roy Lambert [Team Elevate] > |
Wed, Oct 12 2011 8:54 PM | Permanent Link |
Gerald J. Clancy, Jr. | And right you'd be. DBISAM, BTW.
See the response to Roy I just posted. Problem (mine) is fixed. Jerry "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message news:FD07CA01-F304-4854-A296-AAAEE0BFC3A5@news.elevatesoft.com... > Jerry, > > << The end of file is never set. the Next line stays on the last record of > the set and never triggers EOF or exits the "while".. >> > > My first reaction is that you must be wrong - if there was a general EOF > issue with filtered datasets, then EDB would be in a world of hurt (as > would I). > > What version of EDB are you using ? Can you send me an example of the > problem as a small project ? > > Thanks, > > -- > Tim Young > Elevate Software > www.elevatesoft.com |
Thu, Oct 13 2011 3:58 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Jerry
Glad its sorted. Roy Lambert |
Fri, Oct 21 2011 2:14 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Jerry,
<< And right you'd be. DBISAM, BTW. >> Oops, sorry about that. It doesn't happen often, but occasionally I lose track of what newsgroup I'm in. Thanks for the update, -- Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Friday, March 29, 2024 at 03:30 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |