Since Execute method returns True if the user clicked the OK button we have to trap a click on a Cancel button to make sure that given code is not executed. This code displays the File Open dialog box and displays a selected filename after a "successful" call to execute method when the user clicks Open. Note: Execute returns True if the user clicked the OK button, double-clicked a file name in the case of the file dialogs , or pressed Enter on the keyboard.
Execute returns False if the user clicked the Cancel button, pressed the Esc key, closed the dialog box with the system close button or with the Alt-F4 key combination. In order to work with Open dialog or any other at runtime without placing an OpenDialog component on the form, we can use the following code:.
Note: Prior to calling Execute, we can have to set any of the OpenDialog component's properties. Finally, it's time to do some real coding. The whole idea behind this article and few others that are to come is to create a simple MyNotepad application - standalone Windows like Notepad application.
In this article we are presented with Open and Save dialog boxes, so let's see them in action. Steps to create MyNotepad's user interface:. Rename Button1 to btnOpen, Button2 to btnSave. Use Object Inspector to assign the following code to the FormCreate event:. This code sets some of the Open dialog properties as discussed at the beginning of the article.
Add this code for the Onclick event of btnOpen and btnSave buttons:. Run your project. You cannot believe it; files are opening and saving just like with the "real" Notepad. That's it. We now have our own "little" Notepad. So you have to check the folder location from which the application is started. That should not be too difficult! TIniFile is not a descendent of TStrings. I used the TStringList way and it worked perfectly after I found the directory my program exe was in.
Thanks guys , you all are always very very helpful! ExeName Contains the path to the exe file. Show 3 more comments. Create FileName, fmCreate ; try Stream. Size ; Stream. Size ; finally Stream. Free; end; end;. Fastest and simplest way, no need to declare any variables: with TStringList. Agree, added try.. The use of with adds much more evil than the lack of local vars gains.
I use such construct for debugging purposes mostly, it's fast to insert into the code, on any place. Also, if it's short and you do not do additional work in with block, there is no problem with it. For big blocks I don't like with too, because it can lead to unpredictable situations very easy.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. Note: Some functions of this site require your browser to support JavaScript. JavaScript is not enabled in your browser. Without JavaScript, you will not be able to use some features of this site. Either enable JavaScript in your browser or use another computer in which JavaScript is enabled.
Here is a simple Delphi procedure that opens and modifies an existing Microsoft Excel file, saves the file with a new name save as , and finally closes the file. The modification is in the form of a few simple additions to cells in the worksheet of the file. The most relevant parts of the code are highlighted.
0コメント