Delphi LiveBindings如何绑定一个对象(二)(转)

 上一篇我们演示了如何绑定一个对象,这是非常有用的, 不爽的的是在设计期间不能知道对象有几个属性(FisrtName, LastName, Age在设计期间都看不见),

为了解决这个问题我们使用TDataGeneratorAdapter控件

 

一、拖入一个TDataGeneratorAdapter控件并点击Add Field

二、设计完成后连接StringGrid与TDataGeneratorAdapter绑定

 

到些设计已经完成,但我们仍然配置OnCreateAdapter事件 我们在DataGeneratorAdapter创建的字段匹配TPerson类 如果我们运行程序会通过 DataGeneratorAdapter通过TObjectBindSourceAdapter 替换成 AdapterBindSource,

如果我们不需要这个事件, AdapterBindSource会使用DataGeneratorAdapter也可以运行

 

 

 

 NOTE:

   1.DataGeneratorAdapter类似DataSet 可以编辑、提交、保存

         2.当需要一个DataSet时可以使用DataGeneratorAdapter 

 

MyPeople : TObjectList<TPerson>;
procedure TForm1.AdapterBindSource1CreateAdapter(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;

 

 

转载于:https://www.cnblogs.com/pengshaomin/archive/2013/04/23/3038665.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值