Forum > General

Unique Instance Terminate Application

(1/5) > >>

Weitentaaal:
Hi,

i tried to use unique instance and put this in my on create of the main Form

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   if UniqueInstance.PriorInstanceRunning then begin      //raise Exception.Create('Application already Running !');      ShowMessage('Application already Running !');      Close;      Exit;   end; 
i do always get Access Violations. How do i correctly Terminate Application?

bobby100:
This works for me in FormCreate:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if UniqueInstance1.PriorInstanceRunning then  begin    Close;  end;
And I also use this to bring the previous instance to the screen:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.UniqueInstance1OtherInstance(Sender: TObject;  ParamCount: integer; const Parameters: array of string);begin  frmMain.WindowState := wsNormal;  frmMain.Show;end;

Weitentaaal:

--- Quote from: bobby100 on December 05, 2023, 10:21:37 pm ---This works for me in FormCreate:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if UniqueInstance1.PriorInstanceRunning then  begin    Close;  end;
And I also use this to bring the previous instance to the screen:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.UniqueInstance1OtherInstance(Sender: TObject;  ParamCount: integer; const Parameters: array of string);begin  frmMain.WindowState := wsNormal;  frmMain.Show;end;
--- End quote ---

Hey thanks !

works for me too but how do i avoid the Code to continue executing ? The Close wont stop my Application from still loading. i but the same Check ("UniqueInstance1.PriorInstanceRunning") in my Mainform in the OnClose and OnDestroy Events but something will still get executed.

"And I also use this to bring the previous instance to the screen"

didn't thought about this ! thanks, i will use it.

Zvoni:

--- Quote from: Weitentaaal on December 05, 2023, 08:41:57 am ---Hi,

i tried to use unique instance and put this in my on create of the main Form

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   if UniqueInstance.PriorInstanceRunning then begin      //raise Exception.Create('Application already Running !');      ShowMessage('Application already Running !');      Close;      Exit;   end; 
i do always get Access Violations. How do i correctly Terminate Application?

--- End quote ---

"Exit" exits the Function/Procedure this code is in.
You're probably looking for "Terminate"

AlexTP:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Application.Terminate; //betteror

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Halt; //not good for GUI apps

Navigation

[0] Message Index

[#] Next page

Go to full version