You could try something like this:
function IsFirstRecord(ADataSet: TDataSet): Boolean;
var
BmStr: TBookmarkStr;
begin
Result := not ADataSet.IsEmpty;
if not Result then Exit;
Result := ADataSet.Bof;
// if ADataSet is already at BOF there is no point to continue
if not Result then
begin
ADataSet.DisableControls;
try
BmStr := ADataSet.Bookmark;
try
ADataSet.Prior;
Result := ADataSet.Bof;
finally
ADataSet.Bookmark := BmStr;
end;
finally
ADataSet.EnableControls;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsFirstRecord(ADODataSet1) then
ShowMessage('First')
else
ShowMessage('Not First');
end;
For IsLastRecord
implementation simply replace:
ADataSet.Prior -> ADataSet.Next
ADataSet.Bof -> ADataSet.Eof