Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to determine the current record number of a dataset Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Aug-02
Category
Database Others
Language
Delphi All Versions
Views
91
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to determine the current record number of a dataset

Answer:

If the dataset is based upon a Paradox or dBASE table then the record number can be 
determined with a couple of calls to the BDE (as shown below). The BDE doesn't 
support record numbering for datasets based upon SQL tables, so if your server 
supports record numbering you will need to refer to its documentation.

The following function is given as part of a whole unit and takes as its parameter 
any component derived from TDataset (i.e. TTable, TQuery, TStoredProc) and returns 
the current record number (greater than zero) if it is a Paradox or dBASE table. 
Otherwise, the function returns zero.

For dBASE tables the record number returned is always the physical record number. 
So, if your dataset is a TQuery or you have a range set on your dataset then the 
number returned won't necessarily be relative to the dataset being viewed, rather 
it will be based on the record's physical position in the underlying dBASE table.

1   uses
2     DB, DBTables, DbiProcs, DbiTypes, DbiErrs;
3   
4   function GetRecordNumber(Dataset: TDataset): Longint;
5   var
6     CursorProps: CurProps;
7     RecordProps: RECProps;
8   begin
9     { Return 0 if dataset is not Paradox or dBASE }
10    Result := 0;
11    with Dataset do
12    begin
13      { Is the dataset active? }
14      if State = dsInactive then
15        raise EDatabaseError.Create('Cannot perform this operation ' + 'on a closed 
16  dataset'
17      { We need to make this call to grab the cursor's iSeqNums }
18      Check(DbiGetCursorProps(Handle, CursorProps));
19      { Synchronize the BDE cursor with the Dataset's cursor }
20      UpdateCursorPos;
21      { Fill RecordProps with the current record's properties }
22      Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps));
23      { What kind of dataset are we looking at? }
24      case CursorProps.iSeqNums of
25        0: Result := RecordProps.iPhyRecNum; { dBASE }
26        1: Result := RecordProps.iSeqNum; { Paradox }
27      end;
28    end;
29  end;
30  
31  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC