Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Common Header & Footer

edited March 2003 in General
Hi All,

I would like to be able to have a common header and footer (so if it ever
changes, we only have to change it once). I've seen the 'dynamic sub
report' demo but I don't need anything as clever as that.

All the reports in question are sitting one form and all I need todo is
'insert' my common header TppReport into each TppSubReport.

I've tried achieving this may ways, all using the tPpSubReport.Template
property, but nothing seems to work.

Can anyone point me in the right direction?

Cheers
Dave

Comments

  • edited March 2003
    Sorry I should have added...

    What I mean by 'it doesn't work' - I have tried assigning, streaming and
    saving\loading the template from my common header into my subreport, but
    when the report previews it goes into some sort of loop and generates and
    infinite number of pages.

    --
    Cheers
    Dave
  • edited March 2003
    Hi All,

    Has anybody actually managed to achieve this?

    I've scanned this group going back two years and have tried *everything*
    that has been suggested, and nothing seems to work for me. It's either
    creating an infinite number of pages or locking after one (forcing me to
    click cancel). I've tried every combination of
    report/subreport/title/summary/template/autostop/no data behaviour that I
    can think of...

    This is driving me nuts, someone please put me out of my misery :-)

    Cheers
    Dave
  • edited March 2003
    Dave,

    below you find a quote of amessage, I posted some days ago in teh
    Subreports-NG. MAybe it is helpful:

    HTH
    Bernd


    DSL offers some very nice things. We use it e.g. to have common headers and
    footers on our reports, being maintained separately and loaded at runtime.
    Below there is the component which does this. Just drop the
    supreport-component on the report and assign the name of the report you want
    to have loaded at runtime to the edit field where you usually enter the
    caption text.

    Works like a charm :-)

    Bernd


    unit SubreportSOF;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    IniFiles, ppClass, ppBands, ppSubRpt,
    ppTypes, ppVar, ppCtrls;

    type
    TBafSubReport = class(TppSubReport)
    private
    FAutomatedLoad : Boolean;
    FTemplateName : String;
    procedure LoadSubreport;
    protected
    function GetTemplateName : string;
    procedure SetTemplateName(Value: string);
    function GetCaption : string; override;
    public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
    procedure Generate; override;
    procedure StartOfMainReport; override;
    published
    property AutomatedLoad : Boolean read FAutomatedLoad write
    FAutomatedLoad default True;
    property TemplateName : string read GetTemplateName write
    SetTemplateName;
    end;

    implementation

    {$R SubreportSOF.res}

    // -- Create
    constructor TBafSubReport.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    FAutomatedLoad:=True;
    DefaultPropName:='TemplateName';
    DefaultPropEditType:=etEdit;
    end;

    // -- Destroy
    destructor TBafSubReport.Destroy;
    begin
    inherited Destroy;
    end;

    // -- Generate
    procedure TBafSubReport.Generate;
    begin
    Report.AutoStop:=True;
    inherited Generate;
    end;

    // -- LoadSubreport
    procedure TBafSubReport.LoadSubreport;
    begin

    Report.Template.FileName:=ExtractFileDir(Report.MainReport.Template.FileName
    )+'\'+FTemplateName;
    Report.Template.LoadFromFile;

    Report.PrinterSetup.DocumentName:=Band.Report.MainReport.PrinterSetup.Docume
    ntName;
    Report.Engine.State := Report.Engine.State - [esInitialized];
    Init;
    end;

    // -- StartOfMainReport
    procedure TBafSubReport.StartOfMainReport;
    begin
    inherited StartOfMainReport;
    if (AutomatedLoad) and not (Overflow) then begin
    LoadSubreport
    end;
    end;

    // -- SetTemplateName
    procedure TBafSubReport.SetTemplateName(Value: string);
    begin
    if FTemplateName<>Value then begin
    FTemplateName:=Value
    end;
    end;

    // -- GetTemplateName
    function TBafSubReport.GetTemplateName : string;
    begin
    Result:=FTemplateName;
    end;

    // -- GetCaption
    function TBafSubReport.GetCaption : string;
    begin
    Result:='Runtime template';
    end;

    initialization
    ppRegisterComponent(TBafSubReport, 'Demo Components', 0, 0, 'Runtime
    template', 0);

    finalization
    ppUnRegisterComponent(TBafSubReport);

    end.
This discussion has been closed.