【问题标题】:How to access dataset from custom component linked with Live Bindings?如何从与 Live Bindings 链接的自定义组件访问数据集?
【发布时间】:2023-03-20 05:00:01
【问题描述】:

我正在创建自己的从 TMSFMXGrid 派生的 DBGrid。如果使用 Live Bindings 链接,我如何找出链接到该网格的数据集?在设计时,您可以在对象检查器属性 LiveBinding 中看到,但在运行时无法访问。否则我将不得不发布我自己的属性,您可以在其中定义使用的数据集。

【问题讨论】:

    标签: delphi firemonkey delphi-xe3 firemonkey-fm2 livebindings


    【解决方案1】:

    经过几个小时的搜索,我找到了这个解决方案。

    function GetDataSet: TDataSet;
    var
      obj: TColumnDescObject;
      dts: TBaseLinkingBindSource;
      ds: TDataSet;
    begin
      Result := nil;
      if ColumnDescList.Count > 0 then
      begin
        obj := TColumnDescObject(ColumnDescList.Items[0]);
        if Assigned(obj) then
        begin
          dts := obj.ColumnDesc.DataSource;
          if Assigned(dts) then
          begin
            if dts is TCustomBindSourceDB then
            begin
              ds := (dts as TCustomBindSourceDB).DataSet;
              if Assigned(ds) then
              begin
                Result := ds;
              end;
            end;
          end;
        end;
      end;
    end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 2013-03-04
      相关资源
      最近更新 更多