Solved

current record number in ttable?

Posted on 1997-07-06
6
558 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…

821 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