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

dynamically creating report

edited March 2002 in General
I've noticed that when a TppReport sublcass is created that the constructor
and destructor is called twice. Is this normal or expected behavior?

Thanks,
Mike

Comments

  • edited March 2002
    It overrides the TComponent constructor, but shouldn't call it twice. My
    report descendent's constructor is only called once on my project when I
    trace through it. Can you provide us with an example that shows this
    behavior?


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited March 2002
    Actually it looks like loading a template causes the constructor to be called again. The following
    reproduces the behavior:

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ppComm, ppRelatv, ppProd, ppClass, ppReport;

    type
    TMyReport = class(TppReport)
    private
    FSomeField: Integer;
    public
    constructor Create(AOwner: TComponent); override;
    end;

    TForm1 = class(TForm)
    Button1: TButton;
    ppReport1: TppReport;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    FMyReport: TMyReport;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    FMyReport := TMyReport.Create(Self);
    FMyReport.Template.FileName := 'Test1.rtm';
    FMyReport.Template.LoadFromFile;
    FMyReport.Free;
    end;

    { TMyReport }

    constructor TMyReport.Create(AOwner: TComponent);
    begin
    inherited;
    FSomeField := 10;
    end;

    end.


    --

    Mike Kolter
    President, Customizable Components
    http://www.cust-comp.com

  • edited March 2002
    Mike:

    If you remove the loading from file, you will see that it is only created
    once. The second creation is used to stream in the report from the file,
    then it assigns the values to the current report object. If you watch the
    Destroy event, you will see that this gets called 2x as well: once when you
    load and a second time when you free the report object you destroyed.

    Ed Dressel
    Team DM
  • edited March 2002
    Thanks Ed. Seems logical. It's not causing me a problem. I just wanted to know if it was normal
    behavior.

    Mike Kolter
    President, Customizable Components
    http://www.cust-comp.com

This discussion has been closed.