Solved

current record number in ttable?

Posted on 1997-07-06
6
563 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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