Question
“How do I customize the Open/Save To File dialogs?”
Solution
The Report.Template property has an OnCreateDialog event.
The public event is defined as:
1 |
property OnCreateDialog: TppDialogEvent read FOnCreateDialog write FOnCreateDialog; |
And the TppDialogEvent type is defined as:
1 |
TppDialogEvent = procedure(Sender: TObject; aDialog: TObject) of object; |
You can customize the TOpenDialog and TSaveDialog properties by using this
event to gain access to the Dialog object.
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
uses ppTmplat; TMyForm = class(TForm) public procedure myCreateDialogEvent(Sender: TObject; aDialog: TObject); end; procedure TMyForm.FormCreate(Sender: TObject); begin {assign the event-handler} ppReport1.Template.OnCreateDialog := myCreateDialogEvent; end; procedure TMyForm.myCreateDialogEvent(Sender: TObject; aDialog: TObject); var lOpenDialog: TOpenDialog; lSaveDialog: TSaveDialog; begin {get access to the dialog and set properties} if aDialog is TOpenDialog then begin lOpenDialog := TOpenDialog(aDialog); lOpenDialog.InitiaDir := 'c:\myReports\'; end else if aDialog is TSaveDialog then begin lSaveDialog := TSaveDialog(aDialog); lSaveDialog.InitiaDir := 'c:\myReports\'; end; |