Howto Use TSaveDialog: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Howto Use TSaveDialog
| Old | New | Line | |
|---|---|---|---|
| 1 | + | <figure> | |
| 2 | + | <img src="tsavedialog.png" title="tsavedialog.png" /> | |
| 3 | + | <figcaption>tsavedialog.png</figcaption> | |
| 4 | + | </figure> | |
| 5 | + | ||
| 6 | + | Simple guideline: | |
| 7 | + | ||
| 8 | + | 1. Place the [[TSaveDialog|SaveDialog]] widget  on your [[TForm|form]] (anyplace, since it will be not visible).\ | |
| 9 | + | \ | |
| 10 | + | (It is the second left dialog under [[Dialogs tab]]) | |
| 11 | + | 2. Add a [[TMemo|memo]]  in the form. | |
| 12 | + | 3. Add a [[TButton|button]]  in the form. | |
| 13 | + | ||
| 14 | + | The [[IDE Window: Object Inspector|Object Inspector]] will display the properties of the object Button1. Change a [[Property|property]] named 'Caption', with the displayed value 'Button1' to 'Save'. Click on the Events tab on the Object Inspector. Select the box to the right of OnClick: a smaller box with three dots (... ellipsis) appears. Click on this, you are taken automatically into the Source Editor and your cursor will be placed in a piece of code starting. Completion code: | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 17 | + | ||
| 18 | + | procedure TForm1.Button1Click( Sender: TObject ); | |
| 19 | + | begin | |
| 20 | + | if SaveDialog1.Execute then | |
| 21 | + | Memo1.Lines.SaveToFile( SaveDialog1.Filename ); | |
| 22 | + | end; | |
| 23 | + | ``` | |
| 24 | + | ||
| 25 | + | The [[doc:lcl/dialogs/tcommondialog.execute.html|Execute]] [[Method|method]] displays the file save dialog. It returns [[True|true]] when user has selected a file, [[False|false]] when user has aborted. | |
| 26 | + | ||
| 27 | + | The [[doc:lcl/dialogs/tfiledialog.filename.html|Filename]] property returns the full filename including drive and path. | |
| 28 | + | ||
| 29 | + | > **Note:** This control only collects the filename. It does not actually open the file for writing. Your code must do that. | |
| 30 | + | ||
| 31 | + | ## See also | |
| 32 | + | ||
| 33 | + | - [[Howto Use TOpenDialog]] | |
| 34 | + | - [[CopyFile]] | |
| 35 | + | ||
| 36 | + | --- | |
| 37 | + | *From the Free Pascal wiki, page "Howto Use TSaveDialog", as it stood on 2019-09-08 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
