1 unit UniqueInstanceRaw;
2
3 {
4 UniqueInstance is a component to allow only a instance by program
5
6 Copyright (C) 2006 Luiz Americo Pereira Camara
7 pascalive@bol.com.br
8
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or (at your
12 option) any later version with the following modification:
13
14 As a special exception, the copyright holders of this library give you
15 permission to link this library with independent modules to produce an
16 executable, regardless of the license terms of these independent modules,and
17 to copy and distribute the resulting executable under terms of your choice,
18 provided that you also meet, for each linked independent module, the terms
19 and conditions of the license of that module. An independent module is a
20 module which is not derived from or based on this library. If you modify
21 this library, you may extend this exception to your version of the library,
22 but you are not obligated to do so. If you do not wish to do so, delete this
23 exception statement from your version.
24
25 This program is distributed in the hope that it will be useful, but WITHOUT
26 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
28 for more details.
29
30 You should have received a copy of the GNU Library General Public License
31 along with this library; if not, write to the Free Software Foundation,
32 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 }
34
35 {$mode objfpc}{$H+}
36
37 interface
38
39 uses
40 Classes, SysUtils;
41
InstanceRunningnull42 function InstanceRunning(const Identifier: String; SendParameters: Boolean = False; DoInitServer: Boolean = True): Boolean;
43
InstanceRunningnull44 function InstanceRunning: Boolean;
45
46 implementation
47
48 uses
49 SimpleIpc, UniqueInstanceBase;
50
InstanceRunningnull51 function InstanceRunning(const Identifier: String; SendParameters: Boolean; DoInitServer: Boolean): Boolean;
52
53 var
54 Client: TSimpleIPCClient;
55
56 begin
57 Client := TSimpleIPCClient.Create(nil);
58 with Client do
59 try
60 ServerId := GetServerId(Identifier);
61 Result := Client.ServerRunning;
62 if not Result then
63 begin
64 if DoInitServer then
65 InitializeUniqueServer(ServerID);
66 end
67 else
68 // an instance already exists
69 if SendParameters then
70 begin
71 Active := True;
72 SendStringMessage(ParamCount, GetFormattedParams);
73 end;
74 finally
75 Free;
76 end;
77 end;
78
InstanceRunningnull79 function InstanceRunning: Boolean;
80 begin
81 Result := InstanceRunning('');
82 end;
83
84 end.
85
86