Solved

current record number in ttable?

Posted on 1997-07-06
6
568 Views
Last Modified: 2010-05-18
I want to put a label on a form that says

 record ?? of ??

I can get the second bit by the recordcount property, but how do I get the first bit. How can I get the number of the current record in a ttable.

I am not applying any secondary indexes, ranges etc, so its just a straight vanilla table.
0
Comment
Question by:mdoyle
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 50 total points
ID: 1338345
You can use the RecNo property of a table (if you are using D2 or higher & and if your table is a paradox/dbase one) the following works:

label1.caption := 'Record ' + IntToStr(Table1.RecNo) + ' of '+ IntToStr(Table1.RecordCount);

if you are using Delphi 1 the following function [from Borland TIs] work by using BDE functions:

function RecNo(ATable: TTable): LongInt;
  var
    R: RECProps;
    rslt: DbiResult;
    Error: array [0..255] of Char;
  begin
    ATable.UpdateCursorPos;
    rslt := DbiGetRecord(ATable.Handle, dbiNoLock, nil, @R);
    if rslt = DBIERR_NONE then
      Result := R.iPhyRecNum
    else begin
      DbiGetErrorString(rslt, Error);
      ShowMessage('Error Finding Record No: ' + StrPas(Error));
      Result := 0;
    end;
  end;
0
 

Author Comment

by:mdoyle
ID: 1338346
I am using Delphi 1.

The solution you provided looks like it will do the trick, but I can't get it to work. What is the Borland TIs ??

Thanks
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1338347
Here is an example code that works using the above function:
it has a TTable, TDatasource, TDBNaviagator & TDBGrid on a Form.
Note the "uses BDE" in implementation. [TI is Technical Information, btw]

Don't forget to create an "OnDataChanged" event for the datasource.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs,StdCtrls, DB, DBTables, ExtCtrls, DBCtrls,
  Grids, DBGrids;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    DataSource1: TDataSource;
    Table1: TTable;
    Label1: TLabel;
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses BDE;

{$R *.DFM}
function RecNo(ATable: TTable): LongInt;

var

R: RECProps;
rslt: DbiResult;
Error: array [0..255] of Char;

begin
ATable.UpdateCursorPos;
rslt := DbiGetRecord(ATable.Handle, dbiNoLock, nil, @R);
if rslt = DBIERR_NONE then
   Result := R.iPhyRecNum
else begin
   DbiGetErrorString(rslt, Error);
   ShowMessage('Error Finding Record No: ' + StrPas(Error));
   Result := 0;
   end;
end;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
Label1.Caption := 'Record ' + IntToStr(RecNo(Table1)) + ' of ' + IntToStr(Table1.RecordCount);
end;

procedure TForm1.FormCreate(Sender: TObject);

begin
Table1.DatabaseName := 'DBDEMOS';
Table1.TableName    := 'clients.dbf';
DataSource1.Dataset := Table1;
DBGrid1.Datasource  := DataSource1;
DBNavigator1.DataSource := DataSource1;
Table1.open;
end;

end.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mdoyle
ID: 1338348
Sorry to be a bit slow but it's this bit I don't get.

uses BDE;

I did a search for BDE.* and I can't find this library anywhere on my machine. Is it supposed to ship with delphi 1. If so, I must have lost it somewhere along the line.

Where can I get hold of a copy.

Thanks

Martin.
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1338349
Hi Martin,

BDE was an alias to DbiProcs, DbiTypes & DbiErrs. [sorry it was my mistake. i checked the code on D2 not D1]

In Delphi 1 you shoud use
uses DbiProcs, DbiTypes, DbiErrs;

0
 
LVL 7

Expert Comment

by:ahalya
ID: 1338350
Hi Mdoyle,

not that i care, but just wondering ?

what kind of an answer would have "completely" satisfied you (and made you give an "A" ?)

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 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