[Solved] How to read parameter from multiple command line? lazarus / 21-General ---------------------------------------------------------------------- loaded · 2021-06-30 13:59 Hi All, I can read the parameters on the command line with the attached code during the creation of the program. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i project1.exe -dedeCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  i:integer;begin   for I := 1 to ParamCount do   begin   showmessage(ParamStr(I));   // get message dede   end;end; My goal is to be able to read the parameters from the command line while the program is running. So even if the same command line is run repeatedly, I want only one program to run. How can I do that ? ---------------------------------------------------------------------- Bart · 2021-06-30 19:35 IIRC the UniqueInstance has functionality for that. Mind however that relative paths (as commandline params), as they are send to the first instance, are relative to the folder from wich the second instance was invoked (and the first instance doesn't know from where that is). Let me explain. Say you have my.exe, which uses UniqueInstance. Code: [Select] C\foo>my.exe   //starts my.exe, current directory for my.exe = C:\foo C:\foo>cd \bar C:\bar>my.exe myfile The second start of my.exe simply passes it's commandline arguments to the first instance. So this instance will see "myfile" and it will treat that as C:\foo\myfile, since C:\foo is the current directory of the first instance. This is most likely NOT what you intended. So, in order to make this work as expected (e.g. first instance opens C:\bar\myfile), you either have to pass a fully qualified path (my.exe c:\bar\myfile) or make the second instance pass it's current directory to the first instance (which UniquInstance does not do). I did the latter (created a custom fork of UniqueInstance that does just that). Bart ---------------------------------------------------------------------- dbannon · 2021-07-01 02:41 I do what you want in my app, tomboy-ng, when the app starts up, it looks for another version of itself, if it finds one, it might, depending on command line args, send a message to the existing, running, app. I initially used UniqueInstance as Bart suggests but found it lacking in robustness. So, I use the SimpleIPC unit, https://wiki.freepascal.org/SimpleIPC and consider it does a really good job. In my app, I run a non-gui unit first, it processes commandline and tries to make contact with SimpleIPC. If it does find an existing app, it will send an appropriate message and exit. If it does not find an existing app, it decides it is the master and becomes a SimpleIPC server and then, and only then, starts the GUI part of the application. In my LPR file, I have - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...   if ContinueToGUI then begin        Application.CreateForm(TMainForm, MainForm);        Application.CreateForm(TSett, Sett);... The 'ContinueToGUI' method is in the non-gui unit and it returns false if SimpleIPC found another instance running. See https://github.com/tomboy-notes/tomboy- ng/blob/master/source/Tomboy_NG.lpr and perhaps https://github.com/tomboy-notes/tomboy-ng/blob/master/source/cli.pas Davo ---------------------------------------------------------------------- loaded · 2021-07-01 13:31 thank you very very very very much Bart and dbannon. UniqueInstance was installed effortlessly by the online package manager and enabled me to perform the operation I wanted with minimal effort.