Delphi 如何使用活动绑定绑定包含的对象
Malcolm Groves有一个关于TAdapterBindSource和绑定到对象的博客。 这很好,但是如何从类绑定包含的对象呢Delphi 如何使用活动绑定绑定包含的对象,delphi,delphi-xe5,livebindings,Delphi,Delphi Xe5,Livebindings,Malcolm Groves有一个关于TAdapterBindSource和绑定到对象的博客。 这很好,但是如何从类绑定包含的对象呢 TContact = class private FPhoneNumber: String; public property PhoneNumber : String read FPhoneNumber write FPhoneNumber; end; TPerson = class private FAge: Integer; FLast
TContact = class
private
FPhoneNumber: String;
public
property PhoneNumber : String read FPhoneNumber write FPhoneNumber;
end;
TPerson = class
private
FAge: Integer;
FLastname: string;
FFirstname: string;
FContacts: TObjectList;
public
constructor Create(const Firstname, Lastname : string; Age : Integer); virtual;
property Firstname : string read FFirstname write FFirstname;
property Lastname : string read FLastname write FLastname;
property Age : Integer read FAge write FAge;
property Contacts: TObjectList<TContact> read FContacts write FContacts;
end;
TContact=class
私有的
FPhoneNumber:字符串;
公众的
属性PhoneNumber:字符串读取FPhoneNumber写入FPhoneNumber;
结束;
TPerson=类
私有的
FAge:整数;
FLastname:string;
FFirstname:字符串;
FContacts:TObjectList;
公众的
构造函数Create(const Firstname,Lastname:string;Age:Integer);事实上的
属性名:字符串读取FFirstname写入FFirstname;
属性Lastname:字符串读取FLastname写入FLastname;
属性年龄:整数读FAge写FAge;
属性联系人:TObjectList读取FContacts写入FContacts;
结束;
在表格上,我有一份私人清单
MyPeople : TObjectList<TPerson>;
MyPeople:TObjectList;
我还有两个TPrototypeBindSource。
一个用于TPerson,一个用于TContact
procedure TForm1.AdapterBindSourcePersonCreateAdapter(Sender: TObject;
var ABindSourceAdapter: TBindSourceAdapter);
begin
MyPeople := TObjectList<TPerson>.Create;
MyPeople.Add(TPerson.Create('Fred', 'Flintstone', 40));
MyPeople.Add(TPerson.Create('Wilma', 'Flintstone', 41));
MyPeople.Add(TPerson.Create('Barney', 'Rubble', 40));
MyPeople.Add(TPerson.Create('Betty', 'Rubble', 39));
ABindSourceAdapter := TListBindSourceAdapter<TPerson>.Create(self, MyPeople, True);
end;
procedure TForm1.AdapterBindSourceContactCreateAdapter(Sender: TObject;
var ABindSourceAdapter: TBindSourceAdapter);
begin
ABindSourceAdapter := TListBindSourceAdapter<TContact>.Create(self);
end;
procedure TForm1.lstPersonsItemClick(const Sender: TObject; const AItem: TListViewItem);
var
AContacts: TObjectList <TContact>;
begin
AContacts:= TPerson(MyPeople.Items[1]).Contacts;
//self.AdapterBindSourceContact.??? --> How to insert list
//self.AdapterBindSourceContact.DataGenerator.SetList(AContacts, True); --> doesn't work
end;
过程TForm1.AdapterBindSourcePersonCreateAdapter(发送方:ToObject;
var ABindSourceAdapter:TBindSourceAdapter);
开始
MyPeople:=TObjectList.Create;
MyPeople.Add(TPerson.Create('Fred','Flintstone',40));
MyPeople.Add(TPerson.Create('Wilma','Flintstone',41));
MyPeople.Add(TPerson.Create('Barney','browse',40));
MyPeople.Add(TPerson.Create('Betty','browse',39));
ABindSourceAdapter:=TListBindSourceAdapter.Create(self,MyPeople,True);
结束;
过程TForm1.AdapterBindSourceContactCreateAdapter(发送方:ToObject;
var ABindSourceAdapter:TBindSourceAdapter);
开始
ABindSourceAdapter:=TListBindSourceAdapter.Create(self);
结束;
过程TForm1.lstPersonsItemClick(常量发送方:toObject;常量AItem:TListViewItem);
变量
a接触:TObjectList;
开始
a联系人:=TPerson(MyPeople.Items[1])联系人;
//自适配源触点。??-->如何插入列表
//self.AdapterBindSourceContact.DataGenerator.SetList(AContacts,True);-->不起作用
结束;
问题是如何将数据(联系人)加载到第二个TPrototypeBindSource中
一天之后。。。
曾几何时,你得到了一个愿景。
我已将AdapterBindSourceContact(TPrototypeBindSource)更改为TAdapterBindSource
procedure TForm1.lstPersonsItemClick(const Sender: TObject; const AItem: TListViewItem);
var
AContacts: TObjectList <TContact>;
ABindSourceAdapter: TBindSourceAdapter;
begin
AContacts:= TPerson(MyPeople.Items[1]).Contacts;
ABindSourceAdapter := TListBindSourceAdapter<TContract>.Create(self, AContacts);
self.AdapterBindSourceContact.Adapter:= ABindSourceAdapter;
self.AdapterBindSourceContact.Active:= True;
end;
过程TForm1.lstPersonsItemClick(常量发送方:TObject;常量AItem:TListViewItem);
变量
a接触:TObjectList;
ABindSourceAdapter:TBindSourceAdapter;
开始
a联系人:=TPerson(MyPeople.Items[1])联系人;
ABindSourceAdapter:=TListBindSourceAdapter.Create(self,AContacts);
self.AdapterBindSourceContact.Adapter:=ABindSourceAdapter;
self.AdapterBindSourceContact.Active:=真;
结束;
但我不知道这是否是正确的工作方式。用ListBindSourceAdapter强制转换internalAdapter将完成这项工作
with TListBindSourceAdapter<TContact>(AdapterBindSourceContact.internalAdapter) do
begin
SetList(AContacts, False);
Active := true;
end;
使用TListBindSourceAdapter(AdapterBindSourceContact.internalAdapter)执行以下操作
开始
设置列表(A触点,错误);
活动:=真;
结束;
通过快速查看XE5源代码,我会说,AdapterBindSourceContact.SetList(AContacts,False)
应该可以完成这项工作。@StefanGlienke:AdapterBindSourceContact是一个TPrototypeBindSource,没有过程SetList,也就是TAdapterBindSource没有SetList是BindSourceAdapter拥有此方法。TPrototypeBindSource有一个受保护的方法GetInternalAdapter,您可以从中获取它。但我不太熟悉LB体系结构,因为我发现它是BS。是的,有一个集合列表,但我得到一个错误不兼容的类型TGeneratorRecord和TContract。BindSourceAdapter。。。你主要的TAdapterBindSource?一头公牛的排泄物:)