Tapplication is a very important class in Delphi. The Tapplication class is a class used to describe the applications that Delphi compiles. Many characteristic programs can be developed by flexible application of this class.
1 detects if the current Windows program is active:
The Tapplication class has a property--active that can describe whether the currently running program is active and becomes the focus of Windows. The detected code is as follows:
If Application.active=false then showmessage (' Current window not activated ');
2) Get the name of the current program:
The EXEName property of the Tapplication class can return the full file name (including path) of this executable program. The implementation code looks like this: ShowMessage (application.exename);
3 Change the program to minimize the title
The title property of the Tapplication class. This property determines the title of the program when it is minimized, and the caption of the title bar in the window is determined by the Caption property of the form. The code is as follows:
Form1.caption:= ' The title of the window ';
Application.title:= ' The title of the program ';
4 indicates the main window of the program
Windows systems have interfaces that are windows, but generally have a main window. The Tapplication MainForm property can return to the main window of the program.
5) Display message box
Delphi can generate a button that contains the Chinese display, tapplication the MessageBox function. The prototype of this function is as follows: function MessageBox (Text, Caption:char; Flags:longint): Integer
For example: Application.messagebox (' need to save a disk? ', ' cue information ', mb_okcancel);
This function returns an integer value that is specified by the system, for example: The value returned when the "OK" button is pressed is "1", the meaning of the button and the value defined in the system:
Idok 1
IDCANCEL 2
Idabort 3
Idretry 4
Idignore 5
Idyes 6
Idno 7
6 Control the size of the window
You can generally use window handles to resize the window, but you can also use application events to adjust. The approach to implementation is to use the following two procedures:
application.minimized;
Application.restore;
The previous procedure 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 Application Currenthelpfile property enables you to specify the file name of the online Help file that is used by the current program. This property is often used in conjunction with another method. Examples are as follows:
Application.helpfile: = ' online help filename ';
Application.helpjump (' Topics for online Help files ')
With this combination of commands, we can get the system to pop up an online Help file that displays a topic.
8 Create a window dynamically while the program is running
Windows are added to the project at design time, but sometimes we also need to dynamically join the Windows when the program is running, which requires the application CreateForm process, for example:
FORM3:TFORM3; Declaring a window class
Application.createform (TFORM3, FORM3); Create a window
9) Closing the procedure
Although we can close a program using the method of closing the main window, a better way is to use the application terminate process. It can be a more thorough shutdown of the program's effect.
) Destroy property.
Although Delphi provides this attribute, it is not advocated, and if you want to terminate the program calls the terminate process, and the destroy process is generally used to exit the program when the program is hanging, some similar to the end of the task function in Windows. It can not only close the program instance itself, but also release the resources occupied by the program, can achieve the complete elimination of the program to the purpose of the system.