Difference between revisions of "UniqueInstance/de"

From Free Pascal wiki
Jump to navigationJump to search
Line 8: Line 8:
 
* Stellt einen Mechanismus zur Verfügung, Parameter der anderen Instanzen zu empfangen.
 
* Stellt einen Mechanismus zur Verfügung, Parameter der anderen Instanzen zu empfangen.
  
=== How To Use (Component) ===
+
=== Anwendung (Komponente) ===
  
Just drop in the main form of a LCL application
+
Einfach die Komponente auf das Hauptformular platzieren.
  
Properties:
+
Eigenschaften:
  
* Enabled: enables/disables the component
+
* Enabled: aktiviert/deaktiviert die Komponente
* Identifier: used to provides a way to identify the application
+
* Identifier: wird genutzt um die Anwendung zu identifizieren
* UpdateInterval: the interval in milliseconds which the component will monitor messages from new instances. <b>Has meaning only under unix since, under win32, the message is received through the windows message loop</b>
+
* UpdateInterval: der Intervall (ms) in welchem die Komponente Nachrichten von neuen Instanzen empfängt. (Nur unter Linux relevant, da unter Windows die Systemeigene Nachrichtenschleife genutzt wird.
  
 
Event
 
Event
* OnOtherInstance: called when another instance is initiated. Receives the parameters passed to that instance.
+
* OnOtherInstance: wird aufgerufen, falls eine neue Instanz gestartet werden soll und empfängt die ggf. an diese übergebenen Parameter
  
 
=== How To Use (Raw) ===
 
=== How To Use (Raw) ===

Revision as of 19:59, 10 July 2008

Deutsch (de) English (en) español (es) français (fr) polski (pl)

Über

UniqueInstance stellt einen einfachen Weg zur Verfügung, ein mehrfaches Starten der Anwendung zu verhindern.

Funktionen

  • Einfach zu nutzen, es muss lediglich die Komponente auf das Hauptformular gesetzt werden.
  • Stellt einen Mechanismus zur Verfügung, Parameter der anderen Instanzen zu empfangen.

Anwendung (Komponente)

Einfach die Komponente auf das Hauptformular platzieren.

Eigenschaften:

  • Enabled: aktiviert/deaktiviert die Komponente
  • Identifier: wird genutzt um die Anwendung zu identifizieren
  • UpdateInterval: der Intervall (ms) in welchem die Komponente Nachrichten von neuen Instanzen empfängt. (Nur unter Linux relevant, da unter Windows die Systemeigene Nachrichtenschleife genutzt wird.

Event

  • OnOtherInstance: wird aufgerufen, falls eine neue Instanz gestartet werden soll und empfängt die ggf. an diese übergebenen Parameter

How To Use (Raw)

Add uniqueinstanceraw unit to your uses section.

Call the InstanceRunning function: it will return true if there's already a instance running.

There are two variants:

  • Without arguments: will use the executable name as identifier and will not send the command line parameters
  • With two arguments:
    • Identifier: the identifier of the application
    • SendParameters(default = false): send the command line parameters to the already running instance, if any, before quit.

Remarks

  • Tested with win32 (XP SP2) and Linux (Ubuntu Feisty).
  • Version 0.2 requires fpc 2.2.0
  • Although it does not use platform dependent code, the callback mechanic used to pass the command line probably won't work in Linux. This occurs because TSimpleIPCServer under Linux does not call the OnMessage event (At least until some months ago when i tested it). Not more true since version 0.2
  • If you put two TUniqueInstance components in the same application with the same identifier your application won't load.
  • 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.
  • To make sure a application will not avoid other launching you can use a GUID as the Identifier

History

  • 02/10/07 - Version 0.2
    • Based in fpc 2.2.0
    • Implemented parameter reception under unix
    • General optimizations and code clean up
  • 16/12/06 - Initial release. See my blog to know how it began.

Author

Luiz Américo Pereira Câmara

License

Modified LGPL


Download

Version 0.2: Lazarus CCR sourceforge.