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

Error with Template file

edited March 2002 in General
I am doing the following...
When user hits Print Preview i look to see if the Template file exists and
if so then set the Template.FileName to that file and then call
Template.LoadFromFile
This then loads the Template which i originally made in design time.
I want to be able to just drop in another file and that Template to load if
the user requires a different layout of the Report.

I created a Blank report with just a Shape on it and loaded that file, but
after the call to Template.LoadFromFile i get the error box saying

Error reading ppReport1.OnPreviewFormCreate : Invalid property value. Ignore
the error and continue.

If i press ignore then the new Report with the Shape does load up but i
don't want this error box coming up each time the user puts in a new
Template file.
What am i doing wrong please ?

BTW The original report gets it data from a DBPipeline and i do not have any
code in the OnPreviewFormCreate event. In fact i do not have any code in any
of the events.
I am using Delphi5 Enterprise and Report Builder Version 6.02

Thanks
John

Comments

  • edited March 2002
    Hi John,

    register your own dialog.
    I don't show the dialog, but write the unknown property/method into a log
    file, that my human report designer knows - Ah, here's a report I should
    open and save.

    here some code from my main datamodule :


    ppUnRegisterForm(TppCustomTemplateErrorDialog);
    ppRegisterForm(TppCustomTemplateErrorDialog, TdlgTemplateErrorDialog);


    and here the code for the dialog :


    unit UdlgTemplateErrorDialog;

    interface

    uses
    Windows,
    Messages,
    SysUtils,
    Classes,
    Graphics,
    Controls,
    Forms,
    Dialogs,
    ppForms,
    ppTypes,
    ppUtils,
    StdCtrls,
    ExtCtrls;

    type
    TdlgTemplateErrorDialog = class(TppCustomTemplateErrorDialog)
    pnlMain: TPanel;
    pnlBottom: TPanel;
    memErrorMessage: TMemo;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    private
    { Private-Deklarationen }
    protected
    function GetErrorMessage : String; override;
    procedure SetErrorMessage(pmMessage : String); override;
    public
    { Public-Deklarationen }
    end;

    var
    dlgTemplateErrorDialog: TdlgTemplateErrorDialog;

    implementation

    {$R *.DFM}

    uses
    ppReport;

    procedure TdlgTemplateErrorDialog.FormShow(Sender: TObject);
    begin
    PostMessage(Handle, WM_CLOSE, 0, 0);
    end;

    function TdlgTemplateErrorDialog.GetErrorMessage : String;
    begin
    Result := memErrorMessage.Text;
    end;

    procedure TdlgTemplateErrorDialog.SetErrorMessage(pmMessage : String);
    var
    af : TForm;
    msg : String;
    fn : String;
    ms : TMemoryStream;
    begin
    memErrorMessage.Text := pmMessage;

    // log this message
    try
    fn := ExtractFilePath(Application.ExeName) + 'event.report.log';
    ms := TMemoryStream.Create;
    try
    if FileExists(fn) then begin
    ms.LoadFromFile(fn);
    end;
    ms.Seek(0, soFromEnd);

    msg := DateTimeToStr(Now) + ' : ' + pmMessage + #13#10;

    af := Screen.ActiveForm;

    // proprietary code here
    [...].

    msg := msg + '----------------------------------' + #13#10;

    ms.Write(msg[1], Length(msg));

    ms.SaveToFile(fn);
    finally
    ms.Free;
    end;
    except
    on E : Exception do begin
    end;
    end; // try/except
    end;

    procedure TdlgTemplateErrorDialog.FormClose(Sender: TObject;
    var Action: TCloseAction);
    begin
    ModalResult := mrAll;
    end;

    procedure TdlgTemplateErrorDialog.FormCreate(Sender: TObject);
    begin
    // no flicker, this form is a dummy and really shown!
    Left := Screen.Width;
    end;

    end.


    regards,
    Chris Ueberall;

  • edited March 2002
    Thanks for this helpful code Chris (which i will use ;-), but i would really
    like to know why i get the error in the first place.
    Perhaps i should have mentioned that i am quite new to programming, but i
    think what you are saying is to only write the error to a file and not show
    the error box.
    As i said though,i would also like to know why i get the error in the first
    place.

    Thanks
    John



  • edited March 2002
    Hi John,

    Your template has a assigned event methode. You will see that when you open
    the RTM as text file, asuming you used pure ASCII as storage format. it is
    just like opening a form (DFM) in delphi which had assigned the 'FormCreate'
    methode, but was removed from the PAS file.

    regards,
    Chris Ueberall;

  • edited March 2002
    Chris is right, the delphi streaming logic attempts to find this event
    handler, but when none exists on your form unit, then it says that it can't
    find a method for method pointer that it is trying to create and assign.
    There is also a tech tip article which describes how you can lose an event
    handler in the Templates thread of the TechTips newgroup.


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited March 2002
    I see, thanks to you both for the help
    John
This discussion has been closed.