List of all Datasets in TFlexCelReport

Hi,


Before FlexCelReport.Run() i would like to DisableControls for all Datasets in FlexCelReport. How can I get list of all Datasets in TFlexCelReport added with AddTable();

TIA and best regards,
Branko

Hi,

Currently there is no way to list all tables added. It is something being considered because of some other reasons, but the main issue is that tables added with AddTable might not be DataSets at all: they might be for example a TList<> or some other custom types.

The simplest solution would be to add the datasets to a list when you call AddTable. Maybe create some procedure
procedure AddTable(FlexCelReport: TFlexCelReport; Table: TDataSet);
begin
  FlexCelReport.AddTable(Table);
  MyList.Add(Table);
end;

Thank you.

Hi,

I got a little deeper:
type
...
  TXlsReportHelper = class helper for TFlexCelReport
    function DataSets: TArray<TDataSet>;
  end;
...
function TXlsReportHelper.DataSets: TArray<TDataSet>;
var
  oDataTables: TDataSourceInfoList;
  oDataSourceInfos: TArray<TDataSourceInfo>;
  I: Integer;
  L: Integer;
begin
  Result := nil;
  oDataTables := GetDataTables;
  try
    oDataSourceInfos := oDataTables.Values.ToArray;
    for I := 0 to Length(oDataSourceInfos) - 1 do
      // oDataSourceInfos.Table is TVirtualDataTable
      if oDataSourceInfos.Table is TDatasetVirtualTable then
      begin
        L := Length(Result);
        SetLength(Result, L + 1);
        Result[L] := TDatasetVirtualTable(oDataSourceInfos.Table).Data;
      end;
  finally
    oDataTables.Free;
  end;
end;
It works for me, do you have any concerns?

Hi,

I think it is fine. The only thing here is that GetDataTables is an internal method(), so the usual warnings apply. We guarantee that public methods will remain the same for as long as possible, but we change internal methods all the time. The reason is that we try to have a stable public api, but stuff under the hood is changing all the time. For example, when we added support for running reports from a TList<> the public api remained the same (with some extra methods), but methods like GetDataTables changed.

Right now we are going through some changes to support the report designer, which again, have already changed some private methods (the report designer also needs to know which tables you added). But I don't think there is a reason to change GetDataTables for this. I just can't say we are not going to change it in the future if we see a need for that. 

() As sadly delphi doesn't have "internal" modifiers like C#, in delphi internal methods are marked public. The way to know if they are actually internal is to look at the docs:
http://www.tmssoftware.biz/flexcel/doc/vcl/api/FlexCel.Report/TFlexCelReport/index.html


HI,

If in the future I notice that it doesn't work I will use your suggestion. It would be easier (to keep the same method names in TMyFlexCelReport) if the AddTable() and ClearTables() methods were virtual. Can you do that?

As said, we are working in the report designer right now, and the report designer needs information about the tables you added with AddTable, so it is quite likely that the next version will have some way to get the tables. If GetDataTables doesn't exist anymore, it will be because there is some public method that does the same.


So I wouldn't worry. Just keep it as is, and if in the future it broke for any reason, just look for some equivalent method. 

The above should be oDataSourceInfos[I].Table and not oDataSourceInfos.Table. With enable BBcode [I] stands for italic font so [I] is cut off. For the future: the indexing variable must not be I :)