Flexcel - <#include(..)> causes AV if placed after report processes a sheet with with implicit relationship range/band

<#include(..)> causes AV if placed after or in the same sheet where there's a implicit relationship range/band name defined.

How to reproduce:

1-Take Flexcel Include demo project.
2-Add System.Generics.Collections to UMainForm.pas uses clause.
3-Replace RunReport method by:

type
  TMyDetail = class
    private
      FName : string;
    public
      property Name : string read FName write FName;
      class function New(Name : string) : TMyDetail;
  end;

  TMyMaster = class
    private
      FTitle : string;
      FDetails : TObjectList<TMyDetail>;
    public
      constructor Create;
      destructor Destroy; override;
      function AddDetail(Detail : TMyDetail) : TMyMaster;
      class function New(Title : string) : TMyMaster;
      property Title : string read FTitle write FTitle;
      property Details : TObjectList<TMyDetail> read FDetails;

  end;

  TMyTable = class(TObjectList<TMyMaster>)
    public
      class function New : TMyTable;
  end;

{ TMyTable }
class function TMyTable.New: TMyTable;
begin
  Result := TMyTable.Create(True);
end;

{ TMyMaster }
function TMyMaster.AddDetail(Detail: TMyDetail): TMyMaster;
begin
  Result := Self;
  Details.Add(Detail);
end;

constructor TMyMaster.Create;
begin
  FDetails := TObjectList<TMyDetail>.Create(True);
end;
destructor TMyMaster.Destroy;
begin
  FDetails.Free;
  inherited;
end;
class function TMyMaster.New(Title: string): TMyMaster;
begin
  Result := TMyMaster.Create;
  Result.Title := Title;
end;

{ TMyDetail }
class function TMyDetail.New(Name: string): TMyDetail;
begin
  Result := TMyDetail.Create;
  Result.Name := Name;
end;

procedure TMainForm.RunReport;
var
  Report: TFlexCelReport;
  MyTable : TMyTable;
begin
  if not SaveDialog.Execute then exit;

  Report := TFlexCelReport.Create(true);
  MyTable := TMyTable.Create;
  MyTable.Add(
    TMyMaster.New('Master 1')
      .AddDetail(TMyDetail.New('M1 D1'))
      .AddDetail(TMyDetail.New('M1 D2'))
      .AddDetail(TMyDetail.New('M1 D3'))
    );
  MyTable.Add(
    TMyMaster.New('Master 2')
      .AddDetail(TMyDetail.New('M2 D1'))
      .AddDetail(TMyDetail.New('M2 D2'))
    );
  try
    Report.AddTable<TMyMaster>('MyTable', MyTable);
    Report.AddTable('Order Details', DemoTables.OrderDetails);
    Report.SetValue('ReportCaption', 'ORDERS');
    Report.SetValue('Date', Now);
    Report.Run(
      TPath.Combine(GetDataPath, 'Includes.template.xls'),
      SaveDialog.FileName);
  finally
    MyTable.Free;
    Report.Free;
  end;

  if MessageDlg('Do you want to open the generated file?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
    ShellExecute(0, 'open', PCHAR(SaveDialog.FileName), nil, nil, SW_SHOWNORMAL);
  end;


end;

4-In includes.template.xls, add a "MyTable" sheet after Orders sheet.
5-add tags to generate MyTable content at result file, as:
image
6 - Create a range name for MyTable and it's details, as
image

7-Run the program. It's all right:


8-Back to the template, move MyTable sheet, so that now it's placed before Orders sheet.
image
Save it.
9-Click "Go!" again.
And you'll get:
image

ps: the problem is when the detail implicit relationship is active.
If you delete Details range name and MyTable cell B2 (<#Details.Name), the report will run fine, even with MyTable sheet being the first sheet.

Could you please check?
Thanks.

:exploding_head:Could find a workaround:

  • Moved the Detail band to another xls template,
    image
    defined the Details range on this new file
    image

, and used #include on it (includes.template.xls)
image

, getting the expected result (an implicit relationship processed in a sheet preceeding the Orders sheet, where there are other #include's.

Hope it can be fixed.
Now I'll start moving my implicit relationships sections to external templates in the real-world report to check if this workaround fits.

Not at all.
It works for placing data directly, but if in the external included subreport I need to use a <#if(<#Detail.#RowCount> 10;big;not so big)>, or <#if(<#Detail.SectionName.PropertyName = ... )> , it raises an AV again.