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

Report Designer Save and SaveAs Questions

edited July 2002 in General
Greetings,

I provide basic reports with my application and allow the end user to
customize the layout.

I use templates and load the default template from a file with the following
code:
Template.FileName := PathGoUp(ExtractFilePath(ParamStr(0)),1) +'Reports\' +
FRegistry.FReportName;
Template.LoadFromFile;

FRegistry.FReportName in the above code actually loads the filename from a
registry setting.
The filename in this case is Contacts.rtm, the default.

I do not want to allow the end user to modify the default report template,
so I would like to disable the Save menu item in the report designer. How
can I do this?

However, I would let them use the SaveAs menu item to save the report to
another filename. The problem is that they could save to the default
filename of Contacts.rtm. Is there a way to prevent this? If so do you
have some example code?

Along the same lines I do NOT want them to be able to save to any directory,
other than the default directory. Is there a way to keep the user from
selecting a different directory?

Thanks for any like you can shed on these issues.

Mike

Comments

  • edited July 2002
    You can disable the save menu as follows:

    ppDesigner1.Menu.Items.Find('Save').Enabled := False;

    optionally you can instead reassign the event handler to the same one as
    Save As like this:

    ppDesigner1.Menu.Items.Find('Save').OnClick :=
    ppDesigner1.Menu.Items.Find('Save As').OnClick;

    There are few options you have to try to prevent the user from overwriting
    the original template. The simplest is to simply make the file read only
    which would create an error when trying to overwrite the file. To do the
    check programatically you can use the Report.Template.OnLoadStart event to
    check the template name and directory. If the directory is other than the
    application directory you can either notify the user or just change it. The
    same goes for the file name.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited July 2002
    Greetings Alexander,

    You stated: "To do the check programmatically you can use the
    Report.Template.OnLoadStart event to
    check the template name and directory." I do dot see any event with this
    name on the TppReport component in the object inspector. I do see one if I
    type rptContacts.template.OnLoadStart in the editor. How exactly do I
    assign an event to this in the editor. I have never programmed an event
    except for the ones published through the object inspector.

    Thanks

    Mike

    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited July 2002
    I have found something in your Tech -Tips that describes how to do this. I
    tried following this code but get an error when I compile.

    In the Private section:
    procedure ReportTemplateOnLoadStart(Sender: TObject);

    In the Create section:
    rptContacts.Template.OnLoadStart := ReportTemplateOnLoadStart;

    And finally the event:
    procedure TSTContactsPanel.ReportTemplateOnLoadStart(Sender: TObject);
    var
    OrigFilename: String;
    begin
    OrigFileName := rptContacts.Template.FileName;
    ShowMessage(OrigFileName);
    end;

    Here is the error I receive when I compile. What have I done wrong?
    Incompatible types: Parameter list differ

    Thanks

    Mike




    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited July 2002
    Hi Mike,

    TppTemplate.OnLoadStart must be of type 'TppStreamEvent', not
    'TNotifyEvent'.

    TppStreamEvent = procedure(Sender: TObject; aStream: TStream) of object;

    HTH,
    Chris Ueberall;

  • edited July 2002
    Thanks Chris, Got it to work now.

    Mike
This discussion has been closed.