Solved

current record number in ttable?

Posted on 1997-07-06
6
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

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

Title # Comments Views Activity
Base1 Encode/Decode 3 97
enhance the following code 3 50
Microsoft Access 97 and Delphi XE2 9 84
"Could not obtain OLE control window handle" under Delphi XE8 8 73
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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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