Detailed explanation about the TAPPLICATION class in Delphi

zhaozj2021-02-17  51

Detailed explanation about the TAPPLICATION class in Delphi

TAPPLICATION is the type of Delphi application, which is inherited from Tcomponent, declared in unit Forms. And there is a public object Application in Forms. Its method and attribute sets the established basic operations and properties such as creation, run, and destroy applications in the Windows operating system, so simplifying interfaces between users and Windows environments when writing a Windows application with Delphi. The Tapplication packages the following four features:

1, Windows message processing.

2, menu acceleration and keyboard processing.

3, abnormal processing.

4, the context of online help.

Here, you will introduce you to the common properties, methods, and events in TAPPLICATION.

1, attribute

1. 1 property ACTIVE

Property Active indicates whether the application is active and has a focus. Defined as follows:

Property Active: Boolean;

Active is read-only attribute. Active is TRUE when the application is active, otherwise false. The TAPPLICA-TION constructor sets Active for TRUE. If the window or application has a focus, the application is active. When the window of other applications becomes live, the current application is inactive. When the application is turned off, TAPPLICATION The Destructor sets Active to false.

In the application, you can check the value of the properties Active with a timer, thereby determining whether the current application is active in order to make a corresponding process. You can also define the specified operation in Event OnActive and Event Ondeactive.

1.2 Property Dialoghandle

Property DialogHandle provides a mechanism that makes the Delphi application uses non-Delphi dialogs. Defined as follows:

Property Dialoghandle: hwnd;

DialogHandle is required when you create a non-modeled dialog using an API function CreateDialog, and you need to use the message in the application message loop to perform the appropriate operation. For example, when a non-modeled dialog is received (WM_NCActivate), it can assign its handle to DialogHandle, and the dialoghandle is 0 when the dialog is received.

1.3 Property Exename

Properties ExENAME contains an executable application file name extremely path information. Defined as follows:

Property Exename: String;

Exename is read-only attribute. Use Exename to get the file name of the application executable file.

This is a very useful attribute. For example, when running an application f: /media/myapp.exe in an optical disk, you may need to access files in the directory F: / Media / DATA / in or to determine the drive letter where the application is located. At this point, you can use the function ExtractFilePath and ExtractFileName provided by Delphi to resolve the property Exename to obtain information required.

1.4 Property Handle

Attributes Handle provides access to the application main window handle. Defined as follows:

Property Handle: hwnd;

When calling a Windows API function that requires a parent window handle, you need to use the Handle property. For example, a dynamic link library (DLL) in the application may require a parent window handle to make itself populance and display at the foremost. Use Application.Handle to make up a number of windows of the application such that these windows can be minimized, recovered, valid or invalid in the application. Note: When writing a dynamic link library using a VCL form, you should assign the handle of the main window in the main run to the Application.handle property of the dynamic link library. This makes the form of the dynamic link library become part of the primary application. It is important to point out that you will never assign Application.Handle in the EXE application. 1.5 Property HelpFile

Properties HelpFile indicates that the application is used to display the file name of the help content. Defined as follows:

Property helpfile: string;

Using HelpFile is for the application to have a help file that uses a standard Windows Help system. Windows displays a help file indicated by the HelpFile property. To make an application implementation, you must give a value of the file name to the HelpFile property when running, or specify a help file in the Application page of the Project | Options dialog box. By default, HelpFile is an empty string (''), and the application's help method ignores all attempts to display help. If HelpFile includes anything, the method of helping the topic will call up the Windows Help System based on the file name to provide online help.

Note: If the help file of the active window is already specified, the file will take precedence over the application's help file display.

1.6 Property Hint

Property Hint indicates a text string that appears in Help Hint Box. Defined as follows:

Property Hint: String;

The TAPPLICATION.HINT attribute is the Hint value of the mouse that is moving through the control or menu item. This attribute can also be given a string value that provides operations, errors, or other information to the user. Therefore, the use of the HINT attribute can also be: transfer prompt information from the control to another display area, for example, the prompt is displayed in the status bar by the OnHINT event handle. At this time, it is read the HINT attribute. The status is briefly described when the application is performing an action. At this time, it is set up the HINT attribute. When the onhint event occurs, the help tips will appear. Therefore, even if the Hint property of Tapplication is given the title of the status bar, for example, the title of the status bar control shows the current string value of the Hint property, it should also be attributed to the OnHINT event.

The Hint string includes two parts: short tips and long prompts. Short prompt for a concise pop-up prompt; long prompts are spaced between "|" between the short hints, used to display more detailed prompt information in the status bar. You can use the string function GetShorthint and getlonghint from the unit controls to decompose from the Hint property to get short prompts and long prompts.

Note: When the application provides information to the user when providing the user, it should be remembered by default, when the mouse moves through a certain control, the Hint string is reset to the HINT attribute value of the control.

1.7 Property HinthidePause

Properties HintHidePAUSE specifies that the mouse has not been removed from the control or menu item, and the time interval before the hidden help prompt is hidden. Defined as follows:

Property Hinthidepause: integer;

Specify a waiting time in milliseconds in milliseconds, which is set to 2500 milliseconds (2.5 seconds) in a TAPPLICATION constructor. Help prompts for controls or menu items are specified in the HINT property.

Note: The default should pre-determine the value of HinthidePause to be 3 to 5 times more suitable for the HintPause property value.

1.8 Properties MainForm Properties MainForm Uniquely identifies the main form of the application. Defined as follows:

Property Mainform: TForm;

Property MainForm specified by the form does not necessarily equivalent to the main window of the application. The value of the property MainForm must be the first form in all forms created by method Createform, but the form is not necessarily the main window of the application. When new project is created, the mainform property value is automatically set to Form1. You can specify one of MAINFORMs in multiple forms in a plurality of forms. The mainform property cannot be modified at runtime because the property is read-only. The main form is the first form created by the application topic. The main form is closed, that is, the application terminates. In the application, you can call the method Application.MainForm.Close to terminate the application to run, get the value of Application.Mainform.Top, Application.MainForm.Left, etc. to determine the location and size of the current active window.

1.9 Property ShowMainform

Attribute showMAINFORM determines whether a main form is displayed when the application is started. Defined as follows:

Property ShowMainform: Boolean;

The application is controlled with the showMAINFORM attribute and when it displays its main form. TAPPLICATION The constructor is set to showmainform for True. By default, the main form will be displayed, and the main form is indicated in the mainform property.

If you need to hide the main form when the application is started, you should call Application.run to call Application.Run to False, and the Visible property value of the main form is false. This is useful in many implementation OLE automation servers, such as hiding the main form of the server program when starting an automated service.

In addition, if you need to display a flash image (flash) while the application is started and prepared for the application, you need to disable the main form display, which can also be implemented using attribute showMAINFORM. For example, when Delphi is started, the main form is disabled.

1.10 Property Terminated

The Properties Terminated reporter is a Windows message WM_QUIT that receives the termination program. Defined as follows:

Property Terminated: boolean;

Terminated is read-only attribute. This attribute is mainly used to call the ProcessMessages method, the application does not have to try to process Windows messages after stopping. Terminated will be set to TRUE when the ProcessMessages method receives a message WM_QUIT.

The Delphi Application will receive a message WM_QUIT because the main form or application is turned off or because the Terminate method is called.

When the application performs a large intensity, occupying more system resources, the Applicati-ON.ProcessMESSAGES method should be periodically invoked, and the property Application.Terminated is checked to determine if the application is required to terminate the application.

1.11 Property UpdateFormatSettings

Properties UpdateFormatSettings indicate whether the application automatically updates the format setting when the user changes the system configuration. Defined as follows:

Property UpdateFormatSettings: boolean;

Using the UpdateFormatSettings property application can control the automatic update format settings. TAPPLICATION The constructor is set to True. The UpdateFormatSett-Ings property will be checked when the application receives the message WM_WININICHANGE. It is recommended to use the default format setting, which is the local settings of Windows. You can set updateformatse-titings to false to avoid changing formatting during Delphi application execution. 1.12 Property UpdateMetricsTTINGS

The attribute updateMetricSettings property indicates whether the key related settings such as the prompt window font and the icon title are updated. Defined as follows:

Property UpdatemetricSettings: boolean;

The UPDATEFORMATSETTINGS property indicates whether setting changes in the system prompt window font and icon title, etc., is reflected in the relevant settings in the application. TAPPLICATION The initial value of the UPDATEMETRICSETTINGS is True.

2, method

2.1 Method Bringtofront

Method Bringtofront Sets the most recent event window in the application to the front end of all windows on the desktop. It is defined as follows:

PROCEDURE bringtofront;

Use the bringtofront method to find the most recent activity window belonging to the main form and place it at the foremost. The bringtofront method can also test and see if a window is visible and valid before becoming the front-end window. For example, when an application receives an email, you may need to activate a dedicated handler and placed on the front end of the Windows desktop. At this time, you can call the Application.BringTofront method to implement.

2.2 Method CREATEFORM

Method CreateForm method is used to create a new form (Form). Defined as follows:

Procedure Createform (FormClass: TFormClass; VAR Reference);

The Delphi application will always call the Createform method. Therefore, the programmer rarely needs to call the Createform method directly. A typical Delphi project is called a Createform method in the main code portion of the project, and automatically controls the creation of the form when using the Form Designer. You can also call the CreateForm method to dynamically create a form at runtime. The CreateForm method creates a new specified form according to the FormClass parameter and assigns the form to the variable parameter Reference. The owner of the newly created form is the object Application. The application will first call the form created by CreateForm Default as a main form of engineering.

2.3 Method HandleException

Method HandleException provides the default handle for the application's exception. Defined as follows:

Procedure HandleException (Sender: TOBJECT);

Methods HandleException is useful for writing specific components because it produces an event that does not have to respond to Windows messages. In the application, you can use the Onexception event handle to control other exception operations in a custom code. In the application code, if an exception skips all the TRY blocks, the application will automatically call the Handlee-Xception method and will display a dialog that prompts an error. Unless the abnormal object is Eabort, Han-DleException will call the Onexception handle (if present), otherwise call ShowException to display a dialog that prompts an error occurring.

2.4 Method UNHOKMAINWINDOW

The UnHookMainWindow method is used to release the program that is hung by the hookmainwindow method. Defined as follows:

Type TwindowHook = Function: Boolean of Object; Procedure UnHookmainWindow (Hook: TwindowHook);

Use UnHookMainWindows to release the hook window. Indicate the dialog process in the parameter hook. The TwindowHook type is the parameter to call the hookmainwindow method. This parameter is a method pointer that calls the dialog program in the non-Delphi dialog. The dialogue is similar to the window program, which is handled for the dialog, just the different grammatics.

3, event

3.1 Event Onactivate

The onactivate event occurs when the application becomes active. Defined as follows:

TYPE TNOTIFYEVENT = procedure (sender: TOBJECT) OF Object

Property OnActivate: TNOTIFYEVENT;

Use the onACTIVE event to write an event handle to complete the special processing when the application is active. When a Windows application initially runs or its focus forwards from another Windows application back to the current application, the application is active.

3.2 Event ONDEACTIVATE

The ONDEACTIVATE event occurs when the application becomes a non-active state. Defined as follows:

TYPE TNOTIFYEVENT = procedure (sender: TOBJECT) OF Object

Property OndeActivate: TNOTIFYEVENT;

The ONDEACTIVE event can be triggered immediately before the application becomes a non-active state, thereby completing the special processes specified in the event handle. When the user is converted from the current application to another application, the current application's ONDEACTIVE event occurs.

3.3 Events Onexception

Event Onexception occurs when an exception in an application in the application occurs. Defined as follows:

TYPE TEXCEPTIONEVENT = Procedure (sender: TOBJECT; E: Exception) OF Object;

Property OnException: TexceptionEvent;

You can change the default action when an exception occurs in the application can be changed through the Onexception event. In the method TAPPLICATION.HandleException method, the Onexception event handle is automatically called.

The Onexception event is only used to handle an exception that occurs when message processing. An exception that occurs before or after execution of Application.Run does not cause an onException event.

If an exception is ignored in the TRY block of the application code, the application will automatically call the HandleException method. Unless the abnormal object is Eabort, the HandleException will call the Onexception handle (if present), otherwise call ShowException Display a dialog that prompts an error occurring. The TexceptionEvent Type is the type of Onexception event, which points to a method of processing an exception in the application. Parameter sender is an object that triggers an exception, and the parameter E is an exception object.

3.4 Event onhelp

The onhelp event occurs when the application receives a help request. Defined as follows:

TYPE TheLPEVENT = Function (Command: Word; Data: longint; var callhelp: boolean): boolean of ibject

Property onhelp: thelpevent;

Write an event handle with onhelp to complete special processing when requesting help. The HelpContext method and the helpjump method automatically triggers an onhelp event. After the event, CallHelp is set to True to call WinHelp; set the callHelp to False to prevent the VCL from calling WinHelp. All methods in the Delphi application are on the onhelp event. WinHelp is called only when the callHelp parameter in the onhelp event is returned or the onhelp event is not specified to a valid handle. 3.5 Event Onhint

When the mouse pointer moves through a control or menu item and the control or menu item can display the help tip, the event onhint happens. Defined as follows:

TYPE TNOTIFYEVENT = procedure (sender: TOBJECT) OF Object

Property OnHint: TNOTIFYEVENT;

Event handle written with onhint can perform a specified operation when the OnHint event occurs. When the user parks the mouse pointer on a control, and the Hint attribute value of the control is not an empty string (''), the OnHint event will happen. Typically use the onHint event display control or menu item HINT attribute as a title of a panel control (such as tstatusbar), so use the panel (PANEL) as a Status Bar. When the OnHint event occurs, the Hint property is usually specified as a Help Hint and a long prompt that is displayed elsewhere.

3.6 Event OnIdle

The onIdle event occurs when the application becomes idle. Defined as follows:

TYPE TIDEVENT = Procedure (Sender: Tobject; Var Done: Boolean) OF Object;

Property OnIdle: Tidleevent

Write an event handle with OniDel When the application is idle, complete the specified operation. It is idle when the application does not perform any code. For example, the application is idle when the application waits for user input. The TIDELEVENT type is the type of OniDEL event, which points to a method that runs when the application is idle. Object TideElevent has a fabric for the True to variable DONE. When DONE is TRUE, the Windows API function WaitMessage will be called when OniDel returns. WaitMessage enables other applications to get a new message in the application's message queue. When the parameter DONE is false and the application is not busy, the application does not get other applications to get control focus. When the application is turned an idle state, the OniDEL event only occurs once until the parameter done is set to TRUE, the next OniDel event may occur. Application Done is false to eliminate the disorder of the CPU time count, and the count may affect the performance of the entire system.

3.7 Event OnMessage

When the application receives a Windows message, the definition is as follows:

TYPE TMESSAGEVENT = procedure (var Msg: tmsg; var handled: boolean) of object;

Property OnMessage: TMESSAGEVENT

Used to receive Windows messages, the event can receive all the messages sent to Windows. The application generates the event when the application receives a message. Variable MSG is a Windows message type.

转载请注明原文地址:https://www.9cbs.com/read-30728.html

New Post(0)