----Delphi is an object-oriented programming language. Due to its advantages of fully integrated OOP, it makes it a very popular Windows development tool at present. Among the many classes contained in Delphi, Tapplication is a class that plays a very important role. The TApplication class is a class used to describe applications compiled by Delphi. Through flexible application of this class, many distinctive programs can be prepared. Let’s give a few examples in this regard.
----1 Detect whether the current Windows program is activated:
----The Tapplication class has a property - Active, which can describe whether the currently running program is activated and becomes the focus of Windows. The detection code is as follows:
IfApplication.Active=Falsethen
ShowMessage('The current window is not activated');
----2 Get the name of the current program:
----The EXEName property of the Tapplication class can return the full file name (including the path) of this executable program. The implemented code is as follows:
---ShowMessage(Application.ExeName);
----3 Change the title when the program is minimized
----If you observe carefully, you will find that the titles of some programs are not consistent with the names of programs, especially in some English programs. The title bar of the form is relatively long and can accommodate more text. When minimizing, it is often It became a few letters. What works in the middle is the Title property of the Tapplication class. This property determines the title when the program is minimized, and the title of the title bar in the window is determined by the Caption property of Form. The code is as follows:
Form1.Caption:='Title of the window';
Application.Title:='Title of the program';
----In fact, we can also specify the Title attribute value of the Tapplication class when programming. The operation method is to pull down the PRoject menu in the development environment and select the Options menu and the dialog box as shown in Figure 1 (omitted). This effect can also be achieved by filling in the Title column of this dialog box. And because general project files are named in English, the title of the message box pops up during the program operation is in English. But after specifying this property, the titles of all message windows of this program become the value of Title. This makes the program look more complete.
----4 Specify the main window of the program
---The interfaces in Windows systems are all windows, but generally speaking, there is a main window. The MainForm property of Tapplication can return to the main window of the program.
----5 Display message box
----Delphi has many functions and procedures for displaying message boxes. ShowMessage is more commonly used. Although it is very convenient to use, there is a problem, that is, the buttons of this message box are displayed in English. If you want to generate a button with Chinese display, you will need a MessageBox function that helps with Tapplication. The prototype of this function is as follows:
----functionMessageBox(Text,Caption:Char;Flags:Longint):Integer
;
----In this function, the first two items are the displayed prompt information and the title of the message window. Flags is a long integer value used to specify the number and function of the button. Users familiar with Delphi may notice that this function is a little different from the function of the same name provided by Delphi3. It is not that the string parameters in this version are given in the form of characters, and no longer require them to be converted into pointers. We should pay attention to the difference when using it.
----Application.MessageBox('Do you need to save it?','Prompt message',MB_OKCANCEL); The style displayed at runtime is shown in Figure 2 (omitted).
----- Finally, some explanation is given about the return value of this function. In fact, this function returns an integer value, and this value is specified by the system, such as: the returned one when the "OK" button is pressed. The value is "1", while the values of other buttons are listed in Table 1.
----The meaning of the button in Table 1 and the value defined in the system
The meaning of the button The value returned by the function when pressing this button
IDABORT 3
IDCANCEL 2
IDIGNORE 5
IDNO 7
IDOK 1
IDRETRY 4
IDYES 6
----6 Control the size of the window
--- Generally, the window handle can be used to adjust the size of the window, but it can also be used to adjust the size of the window using Application events. The implementation method is to use the following two processes:
Application.Minimized;
Application.Restore;
---The previous process is used to minimize the main window of the program, and the latter process is used to restore the minimized window to its original size.
----7 link online help file
----The CurrentHelpFile property of Application can specify the file name of the online help file used by the current program. This property is often used in conjunction with another method. As an example:
Application.HelpFile:='Online Help File Name';
Application.HelpJump('Theme of Online Help File')
----- Through this command combination, we can make the system pop up an online help file showing a certain topic.
----8 Dynamically create windows when the program is running
----Usually, windows are added to the project during design, but sometimes we also need to dynamically add windows when the program is running. This requires the Application CreateForm process, as shown below:
Form3:Tform3;//Declare window class
Application.CreateForm(TForm3,Form3);//Create window
----9 End the program
----Although we can close a program by closing the main window, a better way is to use the Terminate process of Application. It can achieve a more thorough shutdown of the program.
----10Destroy attribute.
----Although Delphi provides this property, it is not recommended to use it. If you want to terminate the program, you must call the Terminate process. The Destroy process is generally used to exit the program when the program is suspended, which is similar. End task feature in Windows. It can not only close the program instance itself, but also release the resources occupied by the program, achieving the purpose of completely clearing the program out of the system.