| RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Essentials|Books|Link Back |
| TInstanceControl | |||||||||||||||||||||||
| 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.
Instance control? 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. Usage Implementation 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 Here's an example:
Note the LastInstanceHandle parameter in the procedure - it is the handle to the last started instance's main form.
That's it. Don't forget to download the component; and as always if there are any questions or comments please post them on the Delphi Programming Forum.
Next page > Full source code! > Page 1, 2
|
|||||||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· 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? |

