Howto Use TSaveDialog: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 1 | + |  | |
| 5 | 2 | ||
| 6 | 3 | Simple guideline: | |
| 7 | 4 | ||
| 8 | 5 | 1. Place the [[TSaveDialog|SaveDialog]] widget  on your [[TForm|form]] (anyplace, since it will be not visible).\ | |
| 9 | 6 | \ | |
| 10 | 7 | (It is the second left dialog under [[Dialogs tab]]) | |
| 11 | 8 | 2. Add a [[TMemo|memo]]  in the form. | |
| 12 | 9 | 3. Add a [[TButton|button]]  in the form. | |
| 13 | 10 | ||
| 14 | 11 | 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 | 12 | ||
| 16 | 13 | ``` pascal | |
| 17 | 14 | ||
| 18 | 15 | procedure TForm1.Button1Click( Sender: TObject ); | |
| 19 | 16 | begin | |
| 20 | 17 | if SaveDialog1.Execute then | |
| 21 | 18 | Memo1.Lines.SaveToFile( SaveDialog1.Filename ); | |
| 22 | 19 | end; | |
| 23 | 20 | ``` | |
| 24 | 21 | ||
| 25 | 22 | 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 | 23 | ||
| 27 | 24 | The [[doc:lcl/dialogs/tfiledialog.filename.html|Filename]] property returns the full filename including drive and path. | |
| 28 | 25 | ||
| 29 | 26 | > **Note:** This control only collects the filename. It does not actually open the file for writing. Your code must do that. | |
| 30 | 27 | ||
| 31 | 28 | ## See also | |
| 32 | 29 | ||
| 33 | 30 | - [[Howto Use TOpenDialog]] | |
| 34 | 31 | - [[CopyFile]] | |
| 35 | 32 | ||
| 36 | 33 | --- | |
| 37 | 34 | *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).* |
