Delphi in Tapplication detailed

Source: Internet
Author: User
Tags time in milliseconds

Delphi in Tapplication detailed

Transferred from: http://blog.sina.com.cn/s/blog_4d6f55d90100bmv9.html

Tapplication is the type used for the Delphi application, which is declared in the cell forms. Tapplication is the type that Delphi constructs for Windows applications, and its methods and property sets include the established basic operations and properties for creating, running, and destroying applications in the Windows operating system, and are therefore written in Delphi Windows applications simplify the interface between the user and the Windows environment. The tapplication encapsulates the following features:
1, Windows message processing.
2, up and down Federation machine help.
3, menu acceleration and keyboard processing.
4, exception handling.
5. Manage the basic parts of the application defined by the Windows operating system, such as the main window, window class, etc.

Each Delphi application automatically declares an application variable as an instance of the application. If the Delphi application is not a Web server application, then the variable must be of type tapplication. Therefore, Tapplication does not need to appear in the Component Selection Board (component palette) and cannot be visualized in the form designer, so tapplication does not have publication properties (published Properties). However, the public properites of tapplication can be set or modified at design time (Design-time), as in project| The Options dialog box is in the forms and application pages.

The following is an introduction to most of the properties, methods, and events in Tapplication.

1. Attribute active Indicates whether the application is active and has focus. Defined as follows:

Property Active:boolean;

Active is a read-only property. Active is true when the application is active, otherwise false.
Tapplication Constructor (constructor) to set active to true. If the window or application has the focus, the application is active. When the window of another application becomes alive, the current application is inactive. When the application shuts down, the Tapplication (destructor) of the destructor is set to active to false.

In an application, you can use a timer (TTimer) to check the value of a property's active to determine whether the current application is active in order to make the appropriate processing. You can also define the specified action in event onactive and event ondeactive.

2. Attribute Dialoghandle

The Dialoghandle property provides a mechanism for Delphi applications to use a non-Delphi dialog box.
Defined as follows:

Property dialoghandle:hwnd;

When you use the API function createdialog to create a non-modal dialog box, you need to use Dialoghandle, and you need to look at the messages in the application message loop for the appropriate action. For example, when a non-modal dialog box receives an activation message (wm_ncactivate), its handle can be assigned to Dialoghandle, and Dialoghandle is 0 when the dialog box receives an deactivation message.

3. Attribute EXEName

The EXEName property contains the executable application file name with extremely path information. Defined as follows:

Property exename:string;

EXEName is a read-only property. Use EXEName to get the file name of the application executable file.

This is a very useful property. For example, when you run an application f:\media\myapp.exe on a CD, you may need to access the files in directory f:\media\data\ or determine the drive letter where the application resides. You can then use the functions Extractfilepath and Extractfilename provided by Delphi to parse the property exename to get the information you need.

4. Attribute handle

The Handle property provides access to the application's main window handle. Defined as follows:

Property handle:hwnd;

You need to use the handle property when calling a Windows API function that requires a parent window handle. For example, a dynamic-link library (DLL) in an application might require a parent window handle so that it can pop up and appear in the front-end. Use Application.handle to form several windows of your application so that these windows can be minimized, restored, valid, or invalid in your application.
Note: When you write a dynamic-link library that uses a VCL form, you assign a handle to the main window in the main run program to the Application.handle property of the dynamic-link library. This makes the form of a dynamic-link library part of the main application.
In particular, you should never assign a value to Application.handle in an EXE application.

5. Attribute HelpFile

The HelpFile property indicates the file name that the application uses to display Help content. Defined as follows:

Property helpfile:string;

HelpFile is used for applications that have a Help file that uses the standard Windows Help system. Windows displays the Help file indicated by the HelpFile property.
For an application to do this, you must give the HelpFile property a value at run time for the file name, or at design time project| Specify a Help file in the application page of the Options dialog box. By default, HelpFile is an empty string ('), and the Help method of the application ignores all attempts to display help. If HelpFile includes any content, the Help topic method will bring up the Windows Help system to provide online help based on the file name.

Note: If the Help file for the active window is specified, the file will take precedence over the application's Help file display.

6. Attribute hint

The Hint property indicates the text string that appears in the Help Hint box. Defined as
Under

Property hint:string;

The Tapplication.hint property is the hint value of the control or menu item that the mouse is moving through. This property can also be given a string value that provides the user with an action, error, or other information.
You can also use the Hint property to pass a hint message from a control to another display, such as displaying a hint to the status bar by Onhint an event handle. This is the read hint property. A brief description of its state when an action is being performed by the application. This is the setting of the Hint property. The help prompt appears when the Onhint event occurs.
Therefore, even if the Tapplication hint property is given the title of the status bar, such as the title of the status bar control that displays the current string value of the hint property, it should also be attributed to the Onhint event.

The hint string consists of two parts: a short hint and a long hint. Short hints are used for concise pop-up hints, with a vertical line between long hints and short hints "|" Separated to display more detailed information in the status bar. You can use the string functions provided in the unit controls Getshorthint and Getlonghint to decompose from the hint attribute to get short hints and long hints.

Note: When an application provides the user with information about an event that occurs by setting the Hint property, it should be remembered that by default, when the mouse moves through a control, the hint string is reset to the Hint property value of the control.

7. Attribute Hinthidepause

The Hinthidepause property specifies the time interval before the mouse has been removed from the control or menu item, before the help hint is hidden. Defined as follows:

Property Hinthidepause:integer;

Specifies the wait time in milliseconds with Hinthidepause, which is set to 2500 milliseconds (2.5 seconds) in the constructor of the tapplication. The Help tips for a control or menu item are specified in the Hint property.

Note: By default, the value of hinthidepause should be pre-determined to be 3 to 5 times times more appropriate for the value of the Hintpause property.

8. Attribute MainForm

The MainForm property uniquely identifies the main form of the application. Defined as follows:

Property mainform:tform;

The form specified by property MainForm is not necessarily the same as 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 you create a new project, the MainForm property value is automatically set to Form1. Available at design time via project| The Forms page in the Options dialog box specifies that one of them is mainform in multiple forms.

The MainForm property cannot be modified at run time because the property is read-only.

The main form is the first form that is created by the application theme.

The main form is closed and the application terminates.

In the application, you can call method Application.MainForm.Close to terminate the application run, and you can get Application.MainForm.Top, Application.MainForm.Left To determine the position and size of the currently active window, and so on.

9. Attribute Showmainform

The Showmainform property determines whether the main form is displayed when the application starts. Defined as follows:

Property Showmainform:boolean;

The application uses the Showmainform property to control whether and when its main form is displayed.

The Tapplication constructor Showmainform is true. The main form is displayed by default, and the main form is indicated in the MainForm property.

If you need to hide the main form when the application starts, you should call Application.Run before calling Showmainform in the main project file and make sure that the Visible property value of the main form is false. This is useful in many implementations of the OLE Automation server, such as hiding the main form of the server program when the Automation service is started.

In addition, if you need to display a flash picture (Flash) at application startup and prepare for the application's environment, you need to suppress the main form display, which can also be done using the attribute showmainform. For example, when Delphi starts, it disables the display of the main form.

10. Attribute terminated

The terminated property reports whether the application received a terminating program for Windows message wm_quit. Defined as follows:

Property Terminated:boolean;

Terminated is a read-only property. This property is primarily used when calling the ProcessMessages method when an application does not have to try to process Windows messages after stopping.
Terminated will be set to True when the ProcessMessages method receives the message wm_quit.

The Delphi application will always receive message wm_quit because the main form or application is closed, or because the Terminate method is called.

When an application performs an operation that is strong and consumes more system resources, it should periodically call the Application.processmessages method and examine the property application.terminated to determine whether terminating the operation is required to terminate the application.

11. Attribute Updateformatsettings

The Updateformatsettings property indicates whether the application automatically updates the formatting when the user changes the system configuration. Defined as follows:

Property Updateformatsettings:boolean;

The Updateformatsettings property indicates whether settings changes such as the font and icon title of the prompt window in the system reflect changes in the relevant settings in the application.

The initial value of the Tapplication constructor updatemetricsettings is true.

Use the Updateformatsettings property application to control the automatic updating of formatting settings. The constructor for the Tapplication property is true.
The Updateformatsett-ings property is checked when the application receives the message Wm_wininichange. It is recommended that you use the default formatting, which is the local settings for Windows. You can set updateformatse-ttings to false to avoid changing the formatting during the execution of the Delphi application.

12. Method BringToFront

Method BringToFront Sets the most recent active window in the application to the front of all windows on the desktop. Its
Defined as follows:

Procedure BringToFront;

Using the BringToFront method, you can find the most recent active window that belongs to the main form and place it at the forefront.

The BringToFront method can also test and view whether a window is visible (visible) and valid (Enabled) before it becomes the front-end window.

For example, when an application receives a message, it may need to activate the specialized handler and place it at the forefront of the Windows desktop. You can then call the Application.bringtofront method to implement it.

13. Method CreateForm

The method CreateForm method is used to create a new form. Defined as follows:

Procedure CreateForm (Formclass:tformclass; var Reference);

The Delphi application always calls the CreateForm method. It is therefore seldom necessary for programmers to call the CreateForm method directly. A typical Delphi project includes one or more calls to the CreateForm method in the Body Code section of the project, and automatically controls the creation of the form when using the form designer. You can also call the CreateForm method at run time to create a form dynamically.

The CreateForm method creates a new specified form based on 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 CreateForm to create the form by default to the project's main form.

14. Method HandleException

The HandleException method provides the default handle for an application's exception. Defined as follows:

Procedure HandleException (Sender:tobject);

Method HandleException is useful for authors who write specific components, because it can produce an event that does not have to respond to Windows messages. You can use the Onexception event handle in your application to control other exception operations in your custom code.

In application code, if an exception skips all try blocks, the application automatically calls the HandleException method and displays a dialog box that prompts for an error. Unless the exception object is Eabort, HandleException will call the onexception handle (if one exists), otherwise the showexception will be called to display a dialog box prompting for an error to occur.

15. Method Unhookmainwindow

The Unhookmainwindow method is used to release the program that is hung by the Hookmainwindow method in the main form. Defined as follows:

Type Twindowhook = function (var message:tmessage): Boolean of object;

Procedure Unhookmainwindow (Hook:twindowhook);

Use Unhookmainwindow to release the Hook window. Specifies the dialog box procedure in the parameter hook.


The Twindowhook type is the parameter that invokes the Hookmainwindow method. This parameter is a method pointer that invokes a dialog program in a Non-Delphi dialog box. A dialog is similar to a window program in that it handles messages for a dialog box, except that the syntax is different.

16. Event OnActivate

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

Type tnotifyevent = procedure (sender:tobject) of object;

Property onactivate:tnotifyevent;

Write an event handle with the Onactive event to finish specifying special handling when the application becomes active.

When a Windows application initially runs or its focus is transferred from another Windows application back to the current

Application, the application becomes active.

17. Event OnDeactivate

The OnDeactivate event occurs when the application becomes inactive. Defined as follows:

Type tnotifyevent = procedure (sender:tobject) of object;

Property ondeactivate:tnotifyevent;

The Ondeactive event can be triggered immediately before the application becomes inactive, thus completing the special handling specified in the event handle. The Ondeactive event for the current application occurs when a user transitions from the current application to another application.

18. Event Onexception

Event Onexception occurs when an exception that has no handle in the application occurs. Defined as follows:

Type texceptionevent = procedure (sender:tobject; e:exception) of object;

Property onexception:texceptionevent;

The Onexception event can be used to change the default action when an exception with no handle in the application occurs. In the method Tapplication.handleexception method, the Onexception event handle is called automatically.

The Onexception event is used only to handle exceptions that occur during message processing. An exception that occurs before or after Application.Run executes does not cause the Onexception event to occur.

If an exception is ignored in the application code's try block, the application will automatically call Handleexc
Eption method. Unless the exception object is Eabort, HandleException will call the onexception handle (if one exists), otherwise the showexception will be called to display a dialog box prompting for an error to occur.

The texceptionevent type is the type of the Onexception event that points to a method in the application that handles the exception. The parameter sender is the object that throws the exception, and the argument e is the exception object.

19. Event OnHelp

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

Type thelpevent = function (Command:word; Data:longint; var Callhelp:boolean): Boolean of object;

Property onhelp:thelpevent;

Write an event handle with onhelp to complete special handling when there is a request for help. The HelpContext method and the Helpjump method automatically raise the onhelp event.

The Callhelp is set to True after the event occurs, and the VCL calls WinHelp; the callhelp is false to prevent VCL

With WinHelp. All help-related methods in the Delphi application go through the onhelp event. WinHelp is called only if the Callhelp parameter in the onhelp event returns TRUE or if the onhelp event is not specified to a valid handle.

20. Event Onhint

When the mouse pointer moves through a control or menu item and the control or menu item is able to display a help prompt, the event

Onhint occurs. Defined as follows:

Type tnotifyevent = procedure (sender:tobject) of object;

Property onhint:tnotifyevent;

An event handle written with Onhint can perform the specified action when the Onhint event occurs. The Onhint event occurs when the user parks the mouse pointer over a control, and the hint property value of the control is not an empty string (').

The Onhint event is typically used to display the value of a control or menu item hint property as a caption for a panel control (such as Tstatusbar), so the panel is used as the status bar. When the Onhint event occurs, the Hint property is typically specified as a Help prompt (aid Hint) and a long hint (longer Hint) that is displayed elsewhere.

21. Event OnIdle

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

Type tidleevent = procedure (sender:tobject; var done:boolean) of object;

Property Onidle:tidleevent

Write an event handle with Onidel to complete the specified operation when the application is idle. is idle when the application does not execute any code. For example, the application is idle when the application waits for user input.


The tidelevent type is the type of the Onidel event that points to a method that runs when the application is idle. Object

Tidelevent has a default of true for the cloth while the variable is done. When done is true, the Windows API function WaitMessage will be called when Onidel returns. WaitMessage allows other applications to get control of the focus until the application

A new message appears in the message queue. When the parameter done is false and the application is not busy, the application does not give the other application control focus.

The Onidel event occurs only once when the application becomes idle, and the next Onidel event may occur until the parameter done is set to true. The application is set to false to eliminate the CPU time count of the disorder, which can affect the performance of the entire system.

22, OnMessage

When an application receives a Windows message, the event onmessage triggered, as defined below:

Type tmessageevent = procedure (var msg:tmsg; var handled:boolean) of Object;

Preperty onmessage:tmessageevent

Used to receive Windows messages, which can receive all messages sent to Windows by the program. The event is triggered when the application receives a message. The variable msg is the Windows message type.

(This article is from Delphi object-oriented programming thought Liu Yi)

Delphi in Tapplication detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.