[英]Is it possible to find the record that CustomADODataSet is about to scroll to?
I want to make two datasets, DS1
and DS2
, scroll simultaneously. 我想使两个数据集
DS1
和DS2
同时滚动。 These are actually results of queries on same table with different fields. 这些实际上是对具有不同字段的同一表进行查询的结果。 First one is used for UI and has lots of calculated fields and second one is a simple editable dataset with few data fields.
第一个用于UI,具有许多计算字段,第二个是一个简单的可编辑数据集,几乎没有数据字段。 I want both datasets have active record with same
ID
. 我希望两个数据集都具有相同
ID
活动记录。 So, since I assume that DS1
record set is a subset of DS2
's, I just call DS2.Locate
in DS2.AfterScroll
. 所以,因为我认为
DS1
记录集的一个子集DS2
的,我只是叫DS2.Locate
在DS2.AfterScroll
。 But my assumption can be technically violated (due to bad configuration). 但是我的假设在技术上可能会违反(由于配置错误)。 So I want to abort the scrolling process of
DS1
when there's no corresponding record in DS2
. 因此,当
DS2
没有相应的记录时,我想中止DS1
的滚动过程。 By scrolling process I mean changing active record of DS1
and firing DS1.AfterScroll
. 通过滚动过程,我的意思是更改
DS1
活动记录并触发DS1.AfterScroll
。
The following should do what I understand you to mean, in other words the active record of DS2 tracks the active record of DS1. 以下内容应符合我的理解,即DS2的活动记录跟踪DS1的活动记录。 The example uses the
authors
table of the MS demo pubs
database for Sql Server. 该示例使用Sql Server的MS demo
pubs
数据库的authors
表。 Ideally, it would have an integer primary key ID column, but unfortunately authors
doesn't. 理想情况下,它将具有一个整数的主键ID列,但不幸的是
authors
没有。
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
DS1: TADOQuery;
DS2: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
DBNavigator1: TDBNavigator;
DBNavigator2: TDBNavigator;
procedure DS1AfterScroll(DataSet: TDataSet);
procedure FormCreate(Sender: TObject);
protected
DS2au_id,
DS2au_lname,
DS2au_fname : TStringField;
public
end;
[...]
procedure TForm1.DS1AfterScroll(DataSet: TDataSet);
begin
if DS2.Active then
DS2.Locate('au_ID', DS1.FieldByName('au_ID').AsString, []);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DS1.SQL.Text := 'select * from authors';
DS2.SQL.Text := 'select au_id, au_name, au_fname from authors';
DS1.Open;
DS2au_id := TStringField.Create(Self);
DS2au_id.FieldName := 'au_ID';
DS2au_id.Size := 11;
DS2au_id.DataSet := DS2;
DS2au_lname := TStringField.Create(Self);
DS2au_lname.FieldName := 'au_lname';
DS2au_lname.Size := 40;
DS2au_lname.DataSet := DS2;
DS2au_lname := TStringField.Create(Self);
DS2au_lname.FieldName := 'au_fname';
DS2au_lname.Size := 20;
DS2au_lname.DataSet := DS2;
DS2.Recordset := DS1.Recordset;
end;
If you do it this way, the answer to your q 如果您这样做,您的q的答案
Is it possible to find the record that CustomADODataSet is about to scroll to?
是否可以找到CustomADODataSet将要滚动到的记录?
is that you don't need to. 是您不需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.