Forum > General
Unique Instance Terminate Application
Thaddy:
In my opinion testing for a Unique instance should be in the project.lpr file and before application.initialize and application.run are called.
In that case, though, you should not use showmessage, which relies on the LCL, but a native OS messagebox or not at all.
This pattern gives you the least amount of overhead.
Bail out as early as you can....
Weitentaaal:
--- Quote from: Thaddy on December 06, 2023, 10:34:09 am ---In my opinion testing for a Unique instance should be in the project.lpr file and before application.initialize and application.run are called.
In that case, though, you should not use showmessage, which relies on the LCL, but a native OS messagebox or not at all.
This pattern gives you the least amount of overhead.
Bail out as early as you can....
--- End quote ---
Thanks i didn't think of that. i will try to do it here
Weitentaaal:
Added this Code to my lpr:
--- 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 InstanceRunning then begin Application.Terminate; Exit; end;
i thought after "Application.Terminate" was executed, all the Code after it would be ignored. It did not so thats why i was using the Exit in the first place.
Zvoni:
--- Quote from: Weitentaaal on December 06, 2023, 04:37:14 pm ---Added this Code to my lpr:
--- 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 InstanceRunning then begin Application.Terminate; Exit; end;
i thought after "Application.Terminate" was executed, all the Code after it would be ignored. It did not so thats why i was using the Exit in the first place.
--- End quote ---
I‘d say that’s normal since it runs in its own thread and might have to do cleanup
Or just change your if clause to an if then else
If instance running then
Terminate
Else
Regular startup code
KodeZwerg:
I guess in .lpr file I would do like
--- 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 not InstanceRunning then beginfollowed by the basic code to initialize forms etc...
Navigation
[0] Message Index
[#] Next page
[*] Previous page