对于dBase和Paradox数据库,可以通过一些BDE函数获取他们的记录号,但是对于SQL数据库,就不支持了!下面的函数可以接受从TDataSet继承下来的任何控件作为参数!并且返回当前记录的记录号!如果Dataset不是dbase或者Paradox,那么函数返回0!
uses 一些DB单元!
function RecordNumber(Dataset: TDataset): Longint;
var
CursorProps: CurProps;
RecordProps: RECProps;
begin
{ Return 0 if dataset is not Paradox or dBASE }
Result := 0;
with Dataset do
begin
{ Is the dataset active? }
if State = dsInactive then
ShowMessage('Cannot perform this operation on a closed dataset');
{ We need to make this call to grab the cursor's iSeqNums }
Check(DbiGetCursorProps(Handle, CursorProps));
{ Synchronize the BDE cursor with the Dataset's cursor }
UpdateCursorPos;
{ Fill RecordProps with the current record's properties }
Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps));
{ What kind of dataset are we looking at? }
case CursorProps.iSeqNums of
0: Result := RecordProps.iPhyRecNum; { dBASE }
1: Result := RecordProps.iSeqNum; { Paradox }
end;
end;
end;