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

Need example of how to use the onCustomSaveDoc event.

edited July 2002 in General
Greetings,

Does anyone have any code to share on how to use this event?

I simply want to check to see if the user is attempting to save back any
changes to the default template and if so, not allow it. If they are saving
to any filename, other than the default template filename I want the file to
be saved.

Here is what I have so far, but doing this does not save the file.

In the OnLoadStart event I set the path and filename for the report that is
loaded...

//* Add code here to initial the report or data, etc.
procedure TSTContactsPanel.ReportTemplateOnLoadStart(Sender: TObject;
aStream: TStream);
begin
sOrigPath := PathGoUp(rptContacts.Template.FileName,1);
sOrigFilename := copy(rptContacts.Template.FileName,
Length(sOrigPath)+1,
Length(rptContacts.Template.FileName));
dsgContacts.Caption := 'Report Builder: ' + rptContacts.Template.FileName;
end;

Then in the onCustomSaveDoc event I have...

procedure TSTContactsPanel.dsgContactsCustomSaveDoc(Sender: TObject);
var
sNewPath, sNewFilename: String;
begin
sNewPath := PathGoUp(rptContacts.Template.FileName,1);
sNewFilename := copy(rptContacts.Template.FileName,
Length(sOrigPath)+1,

Length(rptContacts.Template.FileName));

dsgContacts.Caption := 'Report Builder: ' + rptContacts.Template.FileName;

if (sOrigFilename = 'Contacts.rtm') and (sNewFilename = 'Contacts.rtm')
then
begin
ShowMessage('You are not allowed to save to the original template.' +
#13#10+
'Please choose SaveAs from the file menu and save to
another filename.');

end;
end;

How do I make this work?

Thanks for any pointers.

Mike

Comments

This discussion has been closed.