|RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Books|Link Back|
|Full source code of a Delphi component that can control the behavior of your application's multiple instances: with the option to limit the number of running instances. Part 2 of the "Controlling the number of application instances" article.|
A promise is a promise. As agreed in the "Controlling the number of application instances" article, here I bring you the full source code of a Delphi component, TadpInstanceControl, designed to control the behavior of your application's multiple instances.
We've already discussed how to "run-once" enable a Delphi application that can check for its previous (running) instance. Along the process, several techniques of implementing such a check were discussed; as well as how to bring your already running application to the foreground, if a user tries to run it "one more time". The article presented a copy-to-go code to control the behavior of your application's multiple instances: with the option to limit the number of running instances.
This time I bring you all the code you need, encapsulated in one single component - including full source code.
TadpInstanceControlThe TadpInstanceControl VCL Delphi component is designed to prevent users from running "too many" instances of an application.
As you will see inside the source (look for the "ThisOnce" TObject type variable), only one copy of this component can be dropped on a form - or an EInstanceControl exception will be raised. This needs to be done since two TadpInstanceControl components would prevent you from running your application even only once.
When the max instances has been reached (MaxInstancesReached procedure inside the source), and the application is going to be terminated, the component hides the application's hidden window to avoid a "flash" on the taskbar.
Installing into a Component palette
TadpInstanceControl: example applicationHere's how to prevent a user from running your Delphi application more that two times:
All graphics (if any) in this feature created by Zarko Gajic.
|· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by: DATE or by TOPIC.
|Stay informed with all new and interesting things about Delphi (for free).|
|Got some code to share? Got a question? Need some help?|