Sign in Join
Wiki copytemporary

UniqueInstance: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: UniqueInstance

OldNewLine
1+## Description
2+
3+### About
4+
5+UniqueInstance provides an easy way to force only one instance per application running at same time. To install this component on your component palette, the easiest way is to use the Lazarus [[Online Package Manager]]. Supports Windows and Linux (macOS prevents multiple instances by default).
6+
7+### Features
8+
9+- Easy of use: just drop a component in the main form
10+- Provides a mechanism to receive the Command Line of the other instances
11+
12+### How To Use (Component)
13+
14+Just drop in the main form of a LCL application (it's on the System tab, look for a red full-circle with the digit "1" in the middle).
15+
16+Properties:
17+
18+- Enabled: enables/disables the component
19+- Identifier: used to provides a way to identify the application
20+- UpdateInterval: the interval in milliseconds which the component will monitor messages from new instances. Has meaning only under unix since, under win32, the message is received through the windows message loop
21+
22+Event
23+
24+- OnOtherInstance: called when another instance is initiated. Receives the parameters passed to that instance.
25+
26+### How To Use (Raw)
27+
28+Add uniqueinstanceraw unit to your uses section.
29+
30+Call the InstanceRunning function: it will return true if there's already a instance running.
31+
32+There are two variants:
33+
34+- Without arguments: will use the executable name as identifier and will not send the command line parameters
35+- With two arguments:
36+ - Identifier: the identifier of the application
37+ - SendParameters(default = false): send the command line parameters to the already running instance, if any, before quit.
38+
39+### Remarks
40+
41+- Tested with win32 (XP SP2) and Linux (Ubuntu 9.04) with fpc 2.4.2.
42+- If you put two TUniqueInstance components in the same application with the same identifier your application won't load.
43+- The Identifier is optional both to the function and the component. In the case it's not used, the executable name is used as an Identifier. The consequence is that if someone changes the exe name another instance will not be identified. In the other hand, if two different applications use the same Identifier one will prevent the other from launching
44+ - TIP: to make sure an application will not prevent another from launching you can use a GUID as the Identifier
45+
46+### History
47+
48+- 11/01/17 - Version 1.1
49+ - Make compatible with fpc 3.0 and above
50+ - Code cleanup
51+- 17/04/11 - Version 1.0
52+ - Fix application being detected as running after a crash under unix
53+ - Fix crash when compiling with Gtk2 widgetset
54+ - Set default values of published properties
55+ - Optimizations and code clean up
56+ - New icon
57+- 02/10/07 - Version 0.2
58+ - Based in fpc 2.2.0
59+ - Implemented parameter reception under unix
60+ - General optimizations and code clean up
61+- 16/12/06 - Initial release. See [my blog](http://lazarusroad.blogspot.com/2006/12/only-one-instance.html) to know how it began.
62+
63+### Author
64+
65+Luiz Américo Pereira Câmara
66+
67+### License
68+
69+Modified LGPL
70+
71+### Download
72+
73+Version 1.1: [Download from GitHub](https://github.com/blikblum/luipack/releases/tag/uniqueinstance-1.1)
74+
75+Recent development moved to GitHub repository: <https://github.com/blikblum/luipack/tree/master/uniqueinstance>
76+
77+You can use SVN client:
78+
79+` svn co https://github.com/blikblum/luipack.git/trunk/uniqueinstance`
80+
81+## See also
82+
83+- [[AppIsRunning]]
84+
85+---
86+*From the Free Pascal wiki, page "UniqueInstance", as it stood on 2020-06-18 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
87+Category: Components

Back to history