Search code examples
delphifiremonkeydelphi-xe3firemonkey-fm2livebindings

How to access dataset from custom component linked with Live Bindings?


I am creating my own DBGrid that is derived from TMSFMXGrid. How can I find out which dataset is linked to this grid, if it is linked using Live Bindings? In design time you can see in object inspector property LiveBinding, but is not accessible in run time. Otherwise I will have to publish my own property, where you could define used dataset.


Solution

  • After many hours of searching, I had found out this solution.

    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;