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

1

7

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.)

Maximamaximal answered 3/4, 2012 at 12:19 Comment(0)
H
8

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;
Hellenist answered 3/4, 2012 at 12:35 Comment(1)
Or else locate something by its primary key [dbase]. Or query on primary key [sql].Trisaccharide

© 2022 - 2024 — McMap. All rights reserved.