Report inheritance |
Top Previous Next |
Report inheritance is described in the User's manual. We will mention some key points here.
If your reports are stored in files then FastReport needs to be told which folder to search for base reports. This folder's content is displayed in the “File>New...” and “Report>Options...” dialogs:
The “TfrxDesigner.TemplateDir” property is used for this purpose. By default it is empty and FastReport searches for base reports in the same folder as the project's executable file (.exe). An absolute or a relative path can be set in this property.
If your reports are stored in a database then code must be written to get a list of available base reports from the DB and to load the base report from the DB. 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 handler must load a base report with the specified TemplateName into the Report object. Here's an example of a 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 use the “TfrxDesigner.OnGetTemplateList” event:
property OnGetTemplateList: TfrxGetTemplateListEvent read FOnGetTemplateList write FOnGetTemplateList;
TfrxGetTemplateListEvent = procedure(List: TStrings) of object;
This event handler returns a list of available templates in the List parameter. Here's an example of a 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;
Fast Report can inherit from previously created reports. For this use the function:
TfrxReport.InheritFromTemplate(const templName: String; InheritMode: TfrxInheritMode = imDefault): Boolean
This function makes the current loaded report inherit from the specified template. The first parameter is the name and path of the parent template, the second sets the inherit mode, which is one of :
Please Note! The search for the parent template is done in reference to the current template. FastReport uses relative paths so there is normally no need to worry about moving applications; the only exception is when the current report and the parent template are placed on different folders or a net path is used.
|