UniqueInstance add functionality
Opened this issue · 0 comments
ozon85 commented
Hello. I suggest add functionality to the TUniqueInstance procedure.Loaded when the first instance is detected.
When the first instance of the program is detected, call the handler of this event:
FOnFirstIntstanceRunned(self, TerminateSelf);
For this we add fields:
FOnFirstIntstanceRunned : TOnFirstIntstanceRunned;
property OnFirstIntstanceRunned: TOnFirstIntstanceRunned read FOnFirstIntstanceRunned write FOnFirstIntstanceRunned;
and a type
procedure TOnFirstIntstanceRunned (Sender : TObject; var TerminateSelfApplication) of object;
Then the code will look like
...
//A instance is already running
//Send a message and then exit
TerminateSelf:=true;//Default choice
if Assigned(FOnOtherInstance) then
begin
IPCClient.Active := True;
if Assigned(FOnFirstIntstanceRunned ) then
FOnFirstIntstanceRunned(self, TerminateSelf);
if Assigned(FOnPrepareParam) then
SendPreparedParams(IPCClient)
else
IPCClient.SendStringMessage(ParamCount, GetFormattedParams);
end;
if TerminateSelf then begin
Application.ShowMainForm := False;
Application.Terminate;
end;
end
...