Solved

current record number in ttable?

Posted on 1997-07-06
6
544 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

18 Experts available now in Live!

Get 1:1 Help Now