Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniqueInstance add functionality #33

Open
ozon85 opened this issue Mar 30, 2022 · 0 comments
Open

UniqueInstance add functionality #33

ozon85 opened this issue Mar 30, 2022 · 0 comments

Comments

@ozon85
Copy link

ozon85 commented Mar 30, 2022

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
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant