• 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;

     

  • 相关阅读:
    iOS设备后台播放音乐方法
    iOS 编译64位FFMPEG
    os8 location authorization 错误.
    IOS 使用新浪微博SDK
    IOS 解析歌词lrc
    IOS 通过button获取cell
    IOS 解析XML文档
    OC .(点)与->(箭头)用法区别
    黑苹果安装合集
    Hello,World
  • 原文地址:https://www.cnblogs.com/pengshaomin/p/3038665.html
Copyright © 2020-2023  润新知