JCL Help:TJclAppInstances

From Project JEDI Wiki
Jump to navigationJump to search

Class Hierarchy[edit]

TJclAppInstances


Summary[edit]

TJclAppInstances allows you to control the number of application instances the user can run.


Pascal[edit]

 public TJclAppInstances = class(TObject);


Description[edit]

TJclAppInstances is a class which allows you to control the number of instances of your application that the user can run simultaneously. In addition the class has a built in method for simple communication among running instances. The application programmer can use this as desired but it's also used to send notifications. For example, when an application starts running or terminates, the class automatically sends a notification about this event to all other instances. To use TJclAppInstances include JclAppInst and somewhere during start up (eg in the project source before the Application.Initialize call) call JclAppInstances.TJclAppInstances.CheckInstance(X) or JclAppInstances.TJclAppInstances.CheckSingleInstance. The first call determines whether or not at most X instances are already running, but does nothing else, while the second call immediately terminates the application when another instance is already running.
To receive notifications you must override the WndProc of your main form and include the following code (or something along those lines):
procedure TForm1.WndProc(var Msg: TMessage); begin if Msg.Msg = JclAppInstances.MessageId then case Msg.WParam of AI_INSTANCECREATED: [another instance was created] AI_INSTANCEDESTROYED: [another instance was destroyed] AI_USERMSG: [user defined message (TJclAppInstances.UserNotify)] end; inherited WndProc(Msg); end;
Note that in both instance creation and instance destruction the Msg.LParam field contains the process ID of the affected instance (which could be the instance itself). Also, notifications as well as user messages are sent to both the main form and to the application message queue. Therefore instead of overriding WndProc you could have also used the TApplication.OnMessage event.


About[edit]

Unit[edit]

JclAppInst


Navigation[edit]

Donator[edit]

Petr Vones


Contribute to this help topic[edit]

This documentation wiki is based on the collaborative effort of Project JEDI users. Your edits are welcome in order to improve documentation quality: edit this page