Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does setting a table's RecNo property not move to that record?

Tags:

delphi

bde

dbase

I have got a TTable component that uses the BDE to access a DBase table. There is no index on the table, so the sort order is the physical order of the records in the table. If I read the RecNo property, it contains the expected number for the current record.

I was under the impression that with this constellation (BDE + DBase) it is also possible to set the RecNo property to move to the corresponding record. But apparently this does not work in my program.

So: Do I remember this incorrectly? Or is there anything special I need to do for this to work?

(Please do not advise about dropping the BDE. I am aware of its issues and we are already migrating away from it.)

like image 408
dummzeuch Avatar asked Apr 03 '12 12:04

dummzeuch


1 Answers

TBDEDataSet implements RecNo setter only for Paradox (not DBase).

unit DBTables;
...
procedure TBDEDataSet.SetRecNo(Value: Integer);
begin
  CheckBrowseMode;
  if (FRecNoStatus = rnParadox) and (Value <> RecNo) then
  begin
    DoBeforeScroll;
    if DbiSetToSeqNo(Handle, Value) = DBIERR_NONE then
    begin
      Resync([rmCenter]);
      DoAfterScroll;
    end;
  end;
end;

You might want to try something generic like this:

procedure SetRecNo(DataSet: TDataSet; const RecNo: Integer);
var
  ActiveRecNo, Distance: Integer;
begin
  if (RecNo > 0) then
  begin
    ActiveRecNo := DataSet.RecNo;
    if (RecNo <> ActiveRecNo) then
    begin
      DataSet.DisableControls;
      try
        Distance := RecNo - ActiveRecNo;
        DataSet.MoveBy(Distance);
      finally
        DataSet.EnableControls;
      end;
    end;
  end;
end;
like image 181
kobik Avatar answered Oct 14 '22 00:10

kobik