Delphi: Get FastReport (fr3) by TFileStream and fix inheritance.

PHOTO EMBED

Mon Aug 29 2022 16:43:44 GMT+0000 (UTC)

Saved by @marcopinero #delphi/pascal

procedure TForm1.Button1Click(Sender: TObject);
var
  fs: TFileStream;
  fn : string;
begin
  //frxReport1.LoadFromFile('c:\Proyectos\rep\reporte.fr3');

  fn := 'c:\Proyectos\reporte.fr3';
  frxReport1.Clear;
  fs := TFileStream.Create(fn, fmOpenReadWrite);
  try
    fs.Position := 0;

    frxReport1.FileName := fn; {<-- The trick using "filename path" }
    frxReport1.LoadFromStream(fs);

  finally
    fs.Free;
  end;
  frxReport1.PrepareReport;
  frxReport1.ShowPreparedReport;
end;
content_copyCOPY

When using inherited report (ParentReport), Fastreport does not get path of Parent correctly. That's why we need to change TfrxReport.ParentReport's path before running (Preparing/Showing) Report file. This is very useful when downloading or copying report file from other sources than local files.