?
Solved

Identify Next record in dataset, without moving to next record.

Posted on 2006-11-13
10
Medium Priority
?
417 Views
Last Modified: 2010-04-05
Good day,

I want to find out, what is the next record in my dataset value, while I loop throw my dataset.
I see there is a next command, but I moves the record marker to the next record, I only want to see the next record in the dataset, without out moving to the next record.

Thanx
Henry
0
Comment
Question by:henryreynolds
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 9

Expert Comment

by:sun4sunday
ID: 17928833
Table1.Prior will go back to the previous record

sun4sunday
0
 

Author Comment

by:henryreynolds
ID: 17928934
Hi sun4sunday

Sorry I think my question is not correctly stated.

I want to do the following.

with qryExtra do
begin
    close;
    sql.Clear;
    sql.Add('select * from Orders order by AccountNo');
    open;
    First;
    while not eof()
    do
    begin
       //get first record in my dataset
       ShowMessage('First Record '+FieldByName('AccountNo').AsString);
     
       //***************
       //get next record, without out moving to next record
       //***display record*****

       // Now get next record
       next;
    end;
end;

I need to see the value of the next record, without moving on to the next record.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17929187
If you want to do something like that, why not use another dataset and hold a copy of the information.
Then all you need to do is keep the new dataset 1 record ahead of the first dataset.

You could use a TClientDataSet for this for example.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:atul_parmar
ID: 17929357
Here is how, (but it is ugly way) :-)
var
  bm : tbookmark;
begin
  bm := Table1.getbookmark;
  Table1.Next;
  Table1.Gotobookmark(bm);
end
0
 
LVL 28

Expert Comment

by:2266180
ID: 17929365
why not something like this:

with qryExtra do
begin
    close;
    sql.Clear;
    sql.Add('select * from Orders order by AccountNo');
    open;
    First;
    while not eof()
    do
    begin
       //get first record in my dataset
       ShowMessage('First Record '+FieldByName('AccountNo').AsString);
     
       //***************
       //get next record, movin gthe cursor (you'll do this anyway ;) )
       next;
       if eof then showmessage('No more records') // ding? dong!
       else
       begin// this is the next record
         ShowMessage(Next Record '+FieldByName('AccountNo').AsString);
         //***display record*****
       end;
    end;
end;

since you are going to move the cursor, just move it before looking at the next record and you're done :) it's just a matter of logic/point of view
0
 

Author Comment

by:henryreynolds
ID: 17929773
Hi ciuly

I understand what you are saying, I only showed this as a example, what I actually asking is , is it possible to determine the next record in the dataset without moving the cursor to the next record.

Thank you mikelittlewood  and atul_parmar  you basically understand what I am asking, I need to keep track of the next record in the dataset, without actually calling next.

I need the next record, because I do some printing, and I must do some validation first before I want to read the next record in the dataset.

Thanx

Henry
0
 
LVL 28

Expert Comment

by:2266180
ID: 17929858
well then something like this will have to do since other then getting the array of records, there is no way of using this approach and not using next to peek into the next record:

while not eof do
  do something with first record
  next;
  if not eof then// do we have a next record?
  begin
    do that validation with the next record
    prior;
  end;// else maybe put some flag that no more records?
  do some stuff on the first record (yes, this will be the first record no matter if above was eof or not)
  next; // move to the next record
end;
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 17930672
Ehm, Guys...

GUYS!!!

Recordsets don't really have a proper "next" record. They're sets. They're not something lineair. Okay, you can sort a set and then go from lowest to highest and then there will be something next after the current record but the whole concept of "Next" in a set is basically flawed.

Basically, all I'm saying is that the "Next" record will depend on the sort order of your recordset. So I don't know why you want to have the "Next" record but you might want to rethink your logic here...

Next to this flaw in logic, the answer is basically 'No'. You have a set and you have a cursor. A cursor just points to some record in your set. Changing the sort order might or might not change your cursor to another record but it will change the next record. And you only have a single cursor per recordset. Nothing can and will change this since -again-recordsets aren't lineair. They're just a collection of data in some random order. Well, random... The sort order determines their randomness...

So why do you need the Next record?
0
 

Author Comment

by:henryreynolds
ID: 17936143
Morning Workshop_Alex

I solved my problem last night, but let me explain why I thought this why.

I am printing invoices on pre-printed stationery using fortes. When a page overflow occur for a account number, then I must not print any ageing totals at the bottom of the paper. My problem was, sometimes they change the type of paper, one type can handle 11 detail lines and the other type can handle 13 detail lines.

Now with fortes it is not so easy to handle the printing, I thought I can check if line 11 or 13 prints, if there is more detail for this account number, if there is more detail then dont print totals, else print totals.

That is why I thought, if I can peak at the next record in the dataset, then I know what I must do next, print totals or advance to next page.

I have solved my problem, the user my select before printing what pre-printed stationery he/she will use, then I calculate how many records there are for a specific account, then I divided the records by 11 or 13, and if there is a reminder  I add one to the page. This why I know what number is my last page for a account, and then I print my totals if the last page occur.
Thanx for helping

Henry
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 200 total points
ID: 17936607
That's exactly what I thought. :-) Trying a complex solution when simpler solutions are also possible.
It also sounds a bit as if you need to create a master-detail relationship in your database. Or maybe just a subselection of your recordset. Something like an account table with accounts and a details table where every detail is linked to an account record. (E.g. by account number.) But I assume you already know this. Am I correct? ;-)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
Loops Section Overview
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question