zoukankan      html  css  js  c++  java
  • 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;

     

  • 相关阅读:
    Labeling Balls(拓扑排序wa)
    Trailing Zeroes (III)(lightoj 二分好题)
    布线问题(prime)
    Let the Balloon Rise(map)
    iframe实现伪ajax
    a标签点击不跳转的几种方法
    Javascript的DOM总结
    Mysql:数据库导入导出
    python之迭代器与生成器
    随机获取数据库的数据
  • 原文地址:https://www.cnblogs.com/pengshaomin/p/3038665.html
Copyright © 2011-2022 走看看