Solved

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

Posted on 2006-11-13
10
364 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
 
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:ciuly
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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:ciuly
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 50 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now