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

杀马特。学长 韩版系。学妹 提交于 2019-12-10 13:17:59

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/9993107/why-does-setting-a-tables-recno-property-not-move-to-that-record

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!