Search Results for

    Show / Hide Table of Contents

    Report inheritance

    The report inheritance was described in the User's manual. We will describe some key moments here.

    If you store your reports in files, you need to set up the folder name which FastReport will use to search the base report. This folder's content will be displayed in the "File|New..." and "Report|Options..." dialogs:

    The TfrxDesigner.TemplateDir property is used for this purpose. By defalt it is empty, FastReport will search for base reports in the folder with your project's executable file (.exe). You can place the absolute or relative path into this property.

    If you store your reports in the database, you have to write a code to load the base report from a DB and to get a list of available base reports. Use TfrxReport.OnLoadTemplate event to load a base report:

    property OnLoadTemplate: TfrxLoadTemplateEvent read FOnLoadTemplate write FOnLoadTemplate;
    
    TfrxLoadTemplateEvent = procedure(Report: TfrxReport; const TemplateName: String) of object;
    

    This event's handler must load a base report with given TemplateName into Report object. Here is an example of such handler:

    procedure TForm1.LoadTemplate(Report: TfrxReport; const TemplateName: String);
    var
      BlobStream: TStream;
    begin
      ADOTable1.First;
      while not ADOTable1.Eof do
      begin
        if AnsiCompareText(ADOTable1.FieldByName('ReportName').AsString, TemplateName) = 0 then
        begin
          BlobStream := TMemoryStream.Create;
          TBlobField(ADOTable1.FieldByName('ReportBlob')).SaveToStream(BlobStream);
          BlobStream.Position := 0;
          Report.LoadFromStream(BlobStream);
          BlobStream.Free;
          break;
        end;
        ADOTable1.Next;
      end;
    end;
    

    To get a list of available templates, you should use the TfrxDesigner.OnGetTemplateList event:

    property OnGetTemplateList: TfrxGetTemplateListEvent read FOnGetTemplateList write FOnGetTemplateList;
    
    TfrxGetTemplateListEvent = procedure(List: TStrings) of object;
    

    This event's handler must return a list of available templates into List parameter. Here is an example of such handler:

    procedure TForm1.GetTemplates(List: TList);
    begin
      List.Clear;
      ADOTable1.First;
      while not ADOTable1.Eof do
      begin
        List.Add(ADOTable1.FieldByName('ReportName').AsString);
        ADOTable1.Next;
      end;
    end;
    

    FastReport can inherit already created reports. For that you should use the following function:

    TfrxReport.InheritFromTemplate(const templName: String; InheritMode: TfrxInheritMode = imDefault): Boolean
    

    This function allows to inherit the current loaded report from the indicated report. The first parameter of the function is a file name of parent template, the second one allows to choose inherit mode:

    • imDefault - derive the dialogue with offer to rename/delete the duplicates
    • imDelete - delete all backup objects
    • imRename - rename all backup objects

    Attention! The search of parent template is done referring the current template, that is necessary to keep catalogues structure at report storage place. Fast Report uses relative paths that's why there is no need to worry about application transfer (the only exception is when the current pattern and parent template are placed on different carriers or net path is used).

    Back to top © Copyright Fast Reports Inc.