TApplication
TApplication encapsulates your Windows application and
performs many
things that help your software work the way its supposed to in the
Windows
environment.
In order for you to use the Application object you must include the Forms unit it in your uses clause. The global object Application is of the class TApplication and is defined by the VCL in the Forms unit: You may not know it but when you create a new application the
windows
created by the application are
Application Title: You can change the Application title this way: procedure TForm1.FormCreate(Sender:
TObject);
or begin
With your application loaded into Delphi you can then go to Project | Options (Shift + Ctrl + F11) and then click on the Application tab and then change the Application Title there. Note if you change the Application Title in the code like in both examples above the Application Title text in Project | Options will not show. If you want the form and taskbar icon to have the same title you can use this code: procedure TForm1.FormCreate(Sender:
TObject);
Application.Active: The Active property will return true if your application currently has input focus. This can be very helpful if you want to know if your application has focus or another application does. An example is if you want to do something when your application has focus, but not do anything when your application does not have focus. Application.ExeName: This can return a string that identifies the fully qualified path of your application. procedure TForm1.Button1Click(Sender:
TObject);
Application.ComponentCount: A simple example of using Applicatin.ComponentCount to list class names: procedure TForm1.Button1Click(Sender:
TObject);
Application Hints: To disable all the fly-over hints in your application you can set ShowHint to false. procedure TForm1.Button2Click(Sender:
TObject);
Here are some application hint examples: This will change the hints color Application.HintColor := clRed; --- How you can display hints in the statusbar First add a TStatusbar component to your form and
procedure TForm1.DisplayHint(Sender:
TObject);
procedure TForm1.FormCreate(Sender:
TObject);
These properties control the period of time for the display of
fly-over
Delphi waits HintHidePause milliseconds before it hides the hint window. procedure TForm1.FormCreate(Sender:
TObject);
When you use HintHidePause, you use it to specify a wait time
in milliseconds,
What Delphi does is waits the HintPause milliseconds before it
displays
the
Here is an example of HintPause, which is in 200 milliseconds: Application.HintPause := 200; Application.Icon: Changing an Applications Icon: procedure TForm1.Button1Click(Sender:
TObject);
Application.ProcessMessages: Example:
begin
Greg Liefs "SUPPRESSING MOUSE AND KEYBOARD EVENTS": http://www.sandbrooksoftware.com/DPSC/Tips/GregLief/gl_q&a64.html Application.Minimize: (Minimize the application to the TaskBar) procedure TForm1.Button2Click(Sender:
TObject);
Application.Terminate: Terminate will end your applications execution, in other words shut it down, what it does is it sets the Terminate property of the TApplication object to true. Terminate waits until all event handlers and any other processing to be completed first. procedure TForm1.Button2Click(Sender:
TObject);
Application.Run: You do not need to call the Application.Run method because Delphi automatically puts it in the main program block in the project. You should never call Application.Create and Application.Destroy either. Example: program DPSCSupp; uses Forms, Unit1 in 'Unit1.pas' {Form1}, {$R *.RES} begin
Application.CreateForm: Is used to create the main form of the application as well as any auto-created forms. Application.OnDeactivate: This happens when an application becomes inactive. Hiding your application when its not being used example: Here is some code that will hide your application when the user clicks off your application and it loses focus. unit Unit1; interface uses
type
var Form1: TForm1;
procedure TForm1.HideMyForm(Sender:
TObject);
procedure TForm1.FormCreate(Sender:
TObject);
end. Run the program and make sure it is not running at full screen and click on an icon on your desktop or on another program. You should see this program minimize. TApplicationEvents: To handle the events of the Application object you can use the
component
designed for this purpose, TApplicationEvents, this is available
in Delphi 5 and Delphi 6.
These are its events available in the Object Inspector:
|