Recent

Author Topic: Open Application with start values on windows  (Read 1132 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
Open Application with start values on windows
« on: May 22, 2022, 02:20:56 am »
I need run application but must be receive a parameters to start some think like that

Admin  "config.txt"

Admin "network.txt"

the file contain some configuration like path and user information




speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Open Application with start values on windows
« Reply #1 on: May 22, 2022, 02:27:51 am »
Have a look at "paramstr" (https://www.freepascal.org/docs-html/rtl/system/paramstr.html).

You could execute a console/command-line with something like:

prog 42 foobar.txt
^0   ^1  ^1

within the program you access the parameters with code like
Code: Pascal  [Select][+][-]
  1. program_exe := paramstr(0);
  2. some_number := paramstr(1);
  3. some_filename := paramstr(2);

In Windows, you can also create a short-cut, then specify parameters, to run the program in a GUI.

cheers
S.
« Last Edit: May 22, 2022, 02:29:44 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
Re: Open Application with start values on windows
« Reply #2 on: May 22, 2022, 03:20:09 am »
Ok i understand but where check parameters on GUI on main form?


Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Open Application with start values on windows
« Reply #3 on: May 22, 2022, 03:51:21 am »
Ok i understand but where check parameters on GUI on main form?
Depends. When you need parameters  :)

Can be in project .lpr or mainform create or when click button or when open file or ...

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Open Application with start values on windows
« Reply #4 on: May 23, 2022, 02:40:23 am »
Ok i understand but where check parameters on GUI on main form?

I am not sure what you mean.
  • To add parameters to a short-cut:
        right-click on the short-cut file (in windows explorer) and select "properties"; you can add the parameters after the EXE name (in Target).
  • To add parameters inside Lazarus IDE (for testing etc):
        select "Run > Run Parameters" then add your parameters into "Command line parameters".
  • To check what parameters there are, I'd suggest using the FormCreate() procedure. Something like the code below.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   a : byte;
  4. begin
  5.   memo1.append('paramcount = '+paramcount.tostring);
  6.   for a := 0 to paramcount do
  7.     memo1.append('param '+a.tostring+' = '+paramstr(a));
  8. end;
cheers
S.

I climbed mighty mountains, and saw that they were actually tiny foothills. :)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
Re: Open Application with start values on windows
« Reply #5 on: May 23, 2022, 11:20:28 pm »
Thanks i never use parameters to start app i was some confuse but i got run the app with parameters....

thanks so much for you help...

 

TinyPortal © 2005-2018