This unit contains definition of XApplet class and declaration of
global variable Applet, which is intended to replace Delphi
VCL Application:TApplication variable. XApplet class is derived from XWindow because it defines application button window.
Note: inherited properties and methods, which has no sense for XApplet or not
recommeded to use, marked with gray color.
Also, such protected ones skipped here at all (because XApplet class can not be ancestor
for other classes).
XApplet <= XWindow <= XVisual <= XClass <= TObject
XApplet properties:
- it is set to True when Applet.Run called and it is set to False before returning from this method. |
- it is set to True in procedure Applet.Terminate and stay the same to the end of executing. |
- first created (after Applet) XWindow (or its descender, i.g. XForm) becomes "main" and it is returned here. |
- usually it is False and this means It is used in method Run to unload OleAut32.dll and Ole32.dll at the start of running (Delphi by default is loading these both, and it takes about 1,5 MBytes of memory) |
Properties, inherited from XWindow:
- extended window style. Default is 0. Other possible flags are WS_EX_ACCEPTFILES, WS_EX_APPWINDOW,
and more. Look at CreateWindowEx topic in Win32.hlp to get more info about extended window
style flags. In particular, it is possible set flags WS_EX_TOOLWINDOW to remove applet from tasks list available by ALT-TAB keys and WS_EX_TOPMOST to place its forms on top of other windows on screen. Set ExStyle property before creating a window. And it is possible to change style later. |
- possible states are: wsNormal, wsMinimized, wsMaximized. Default is wsNormal. |
Properties inherited from XVisual:
- Default is True. Set it to False to void painting of object (form, control) and
taking its rectangle into account while autoplacing of aligned controls. In XApplet, making it False vanishes applet button from system task bar but not from tasks list (available by ALT-TAB). To make applet also unavailable by ALT-TAB, add also WS_EX_TOOLWINDOW flag to Applet.ExStyle property. |
Properties inherited from XClass:
XApplet methods:
- XApplet can not have parent. So it's constructor is reintroduced to eliminate AParent parameter. |
- call this method after creating of main window (and possibly other windows) of applet. It starts message dispatchering loop, which works while applet is running. This loop is finishing either by receiving message WM_QUIT (sended anywhere in program by calling PostQuitMessage) or by calling Applet.Terminate. |
- call it to start terminating process of applet. After this call property Terminated retrns True. And when control is returned into applet messages loop, it is finishing, and applet is closing. |
- minimizies applet, hiding its windows and deactivating its applet button (if it is visible). This method is called automatically when main window receives WM_SYSCOMMAND message with SC_MINIMIZE command (thus is, when user clicks onto minimize box of main window). |
- restores applet windows in its last state after minimizing. Called automatically on activating the applet (e.g. by click on applet button, or swithcing to it with ALT-TAB key). |
- this method has to be called when new windowed descendent of XVisual is created.
You do not need to call it manually when override constructor of XVisual - it is called in
inherited constructor. Applet stores list of all windowed visual elements (forms, windowed controls) to redirect them messages from messages queue. |
- similar above, this method is called from destructor of XVisual. And You usually do not need call it manually. |
Methods, inherited from XWindow:
Methods, inherited from XVisual:
In XApplet, CreateWindow can be called to force creating applet button window and applet's forms created before. Any way it is called when method Run is called, so You do not usually need call CreateWindow manually. |
Methods inherited from XClass:
Events of XApplet object:
- called in Applet.Minimize. Add your handler here to do something when applet is minimized. |
- called in Applet.Restore. Add your handler here to do something when applet is restored. |
- called in Applet.WndProc when message WM_ACTIVATE is received and it leads to activating of applet. Add your handler to do something on activating of applet. |
- called when applet is deactivating. Add your handler to do something in that case. |
- called for each message. You may add your handler by the usual way, assigning it
to this event. But if You use some XCL classes which can attach to this event, or if You
are creating such class yourself, please use technique of joining by chains:
This above procedure of attaching/deattaching is not mandatory here but only recommended. Therefore, I insist upon using this techinique in joining to events which are named with prefix On_ (e.g. XForm.On_AutoSizeForm, which is intended to make possible FormAutoSizer add-on). |
Event, ihherited from XWindow:
XEventAccept = procedure( Sender :
TObject; var Accept : Boolean ); - use this event to decide if window can be closed in response to Windows message WM_CLOSE. If not, set Accept to False before return. In XApplet I suggest You do not use this event but instead use such event of main window. |
Other definitions of XApplets.pas unit:
- this global variable represents a single instance of XApplet class. Create it in dpr-file and use XApplet class method Run to execute your applet. |
- use this procedure instead of API call ShowWindow( Wnd, ShowCommand) to perform showing/hiding window without animation (fast). |
Tasks.
You must not to descend objects from XApplet, because a single variable Applet : XApplet is alredy defined in XApplets.pas unit. Just call constructor for it and call its method Run to start executing of applet.
I found that here is the best place to show as an example
how to start XCL project
which does not use VCL forms, controls and components and is extremely
small.
1st way (complex). First,
create new project in Delphi. Then, open Project Manager and remove Unit1 from list. Open
Project|Options and in tab sheet Directories/... clear search directories list. Save Your
project (I prefer to create subdirectory for it in folder, where XCL units are stored). In
menu View|Project source (in D3) or Project|View source (in D4) open .dpr-file which
represents Delphi project but actually is pascal program. Delete reference to Forms in
uses clause, and add references to Windows and Messages units. Also delete all lines
between begin and end statements and save project. If You uncheck now options 'Local
symbols', 'Refernce info' (in tabsheet Compiler of Project|Options dialog) and build this
project, You obtain very small application (about 17Kbytes). But it can not do nothing and
if You want to add some code to it, You will need to create and show at least main window
and some controls. And application becomes big again. If not XCL...
Add now to uses clause of dpr-file references to XForms, XApplets, XClasses,
XWindows, XStrUtils, XVisuals, XGraphics (theses seven are minimal set of modules You
need) and other XCL and your units, which You want been referenced here. References to
seven above minimal necessary units have to be qualified with in operator (I suppose here
that your XCL project is located in subfolder of directory with XCL units):
uses Windows, Messages, XForms in '..\XForms.pas', XApplets in '..\XApplets.pas', XClasses in '..\XClasses.pas', XWindows in '..\XWindows.pas', XStrUtils in '..\XStrUtils.pas', XVisuals in '..\XVisuals.pas', XGraphics in '..\XGraphics.pas', MyMain; |
2nd way. If You do so as
above, You need to add here refernces to other XCL units if You receive message 'can not
found some_name.pas unit'. If You do not like it, just open Project|Options
dialog and in tab 'Directories/..' add directory where XCL units are located (if You
followed to my advice to locate project in subfolder of such directory, it is sufficient
to write '..' (without commas) as a single path). In that case it is possible to list only
XForms and XApplets units in uses clause of XCL project file, and without full qualifying
of names as above.
Then, write code similar following between begin and end statements (pay
attantion that existing global variable Applet is referred here and You must not create
other instances of XApplet class in your project):
Applet := XApplet.Create; MyForm := XMyForm.Create(Applet); Applet.Run; |
Second line here is calling your XMyForm class constructor, which declaration (I suppose) is located in your unit (e.g. mymain.pas) and such unit is listed in uses clause of this dpr-file (didn't forget to do it?). Another, You may create instance of XForm without deriving new one from it and just write:
Applet := XApplet.Create; XForm.Create; Applet.Run; |
As You see You even do not need to store created form in variable (because it is the first window, so it can be referenced as Applet.MainWindow). Try now to build this project and run it. You will see simple applet with one nonamed window, and even its button on system start bar has no caption. And if You made all right, its size must be about 28Kbytes.
3rd way (easy). Open project Template.dpr and Save as YourName.dpr in directory where You wish (I recommend to use subdirectory of folder where XCL units are stored, and set in Project options/Directories/Search path '..'). Start changing it and compiling it.