为什么设置表的RecNo属性不会移动到该记录? [英] Why does setting a table's RecNo property not move to that record?

查看:73
本文介绍了为什么设置表的RecNo属性不会移动到该记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TTable组件,该组件使用BDE访问DBase表。表上没有索引,因此排序顺序是表中记录的物理顺序。如果我读了RecNo属性,它包含当前记录的预期数字。

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.

我的印象是,有了这个星座(BDE + DBase),这也是可能的设置RecNo属性以移动到相应的记录。但这显然在我的程序中不起作用。

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?

(请不要建议删除BDE。我知道它的问题,我们已经在迁移

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

推荐答案

TBDEDataSet 实现 RecNo 设置器仅用于 Paradox (不是 DBase )。

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;

这篇关于为什么设置表的RecNo属性不会移动到该记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆