Link to home
Start Free TrialLog in
Avatar of henryreynolds
henryreynoldsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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
Avatar of sun4sunday
sun4sunday
Flag of India image

Table1.Prior will go back to the previous record

sun4sunday
Avatar of henryreynolds

ASKER

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.
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.
Avatar of atul_parmar
Here is how, (but it is ugly way) :-)
var
  bm : tbookmark;
begin
  bm := Table1.getbookmark;
  Table1.Next;
  Table1.Gotobookmark(bm);
end
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
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
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;
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?
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
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial