JCL Help:TJclAppInstances - Project JEDI Wiki

JCL Help:TJclAppInstances

From Project JEDI Wiki

Jump to: navigation, search


[edit] Class Hierarchy


[edit] Summary

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

[edit] Pascal

 public TJclAppInstances = class(TObject);

[edit] Description

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.

[edit] About

[edit] Unit


[edit] Navigation

[edit] Donator

Petr Vones

[edit] Contribute to this help topic

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

Personal tools
Project JEDI
Code Library
Visual Component Library
Version Control System
Math Library
Code Formatter