Mirror

How to retrieve row information in a TDBGrid (Views: 28)


Problem/Question/Abstract:

I would like to have a message displayed which shows the actual row in a DBGRid; i.e. "row 32 of 144". How can I achieve this?

Answer:

You could query the BDE with two calls to get the number of records and the cursor position like below:

function GetNumRecords(T: TTable): LongInt;
function GetRecordNumber(DataSet: TDataSet): Longint;

function TMainForm.GetNumRecords(T: TTable): LongInt;
var
  Count: LongInt;
begin
  Check(DbiGetRecordCount(T.Handle, Count));
  Result := Count;
end;

function TMainForm.GetRecordNumber(DataSet: TDataSet): Longint;
var
  CursorProps: CurProps;
  RecordProps: RecProps;
begin
  with DataSet do
  begin
    Check(DbiGetCursorProps(Handle, CursorProps));
    UpdateCursorPos;
    Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps));
    Result := RecordProps.iSeqNum;
  end;
end;

<< Back to main page