Recent

Author Topic: Force parameters of my application  (Read 1169 times)

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Force parameters of my application
« on: March 16, 2025, 04:19:35 am »
Good morning, friends, I have a question.
How can I start my application with predefined command parameters and have it work on Windows and Linux?
For example, I want my application to always start automatically with:
Code: Pascal  [Select][+][-]
  1. application1.exe --winner
Please help.  :(
I love desktop software
https://www.ericksystem.com

cdbc

  • Hero Member
  • *****
  • Posts: 2064
    • http://www.cdbc.dk
Re: Force parameters of my application
« Reply #1 on: March 16, 2025, 07:33:04 am »
Hi
Just set '--winner' as a default option and the check parameters, if none are provided it continues with the default, but if a param is provided it overrides the default... Easy Peasy  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Re: Force parameters of my application
« Reply #2 on: March 16, 2025, 09:17:46 pm »
Thank you very much, my friend. I found it in
Run --> execution parameters --> command line parameters
Greetings and thanks  :)
I love desktop software
https://www.ericksystem.com

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Re: Force parameters of my application
« Reply #3 on: March 18, 2025, 04:42:12 pm »
Hi friends, I've realized that this trick only works in design mode of my application. Is there a way for my app to start automatically with the '--winner' parameter, without needing the terminal or extra files, all from within my app?  :( Please help.
I love desktop software
https://www.ericksystem.com

cdbc

  • Hero Member
  • *****
  • Posts: 2064
    • http://www.cdbc.dk
Re: Force parameters of my application
« Reply #4 on: March 18, 2025, 05:23:03 pm »
Hi
As described in post #1, it could look like this attached project
Regards Benny

edit: uploaded new zip, with the pas-file too  :o
« Last Edit: March 18, 2025, 07:04:02 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Re: Force parameters of my application
« Reply #5 on: March 18, 2025, 06:00:53 pm »
Hi friend, thank you very much, but I can't find where you put the '--winner' parameter in the example.
If you could help me, please.
I love desktop software
https://www.ericksystem.com

cdbc

  • Hero Member
  • *****
  • Posts: 2064
    • http://www.cdbc.dk
Re: Force parameters of my application
« Reply #6 on: March 18, 2025, 06:25:55 pm »
Hi
Ok, I spelled it out for you, look for the word 'HERE':
Code: Pascal  [Select][+][-]
  1. unit view.main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls;
  9.  
  10. type
  11.   TParam = (prNone, prWinner, prLooser, prEtc); /// <--- params to app
  12.   { TfrmMain }
  13.   TfrmMain = class(TForm)
  14.     stbInfo: TStatusBar;
  15.   private
  16.     fStartParam: TParam; { <--- HERE }
  17.   public
  18.     procedure AfterConstruction; override;
  19.   end;
  20.  
  21. var
  22.   frmMain: TfrmMain;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TfrmMain }
  29.  
  30. procedure TfrmMain.AfterConstruction;
  31. var ls: string;
  32. begin
  33.   inherited AfterConstruction;
  34.   fStartParam:= prWinner; { <--- HERE }
  35.   if ParamCount >= 1 then begin
  36.     if ParamStr(1) = '--looser' then fStartParam:= prLooser
  37.     else if ParamStr(1) = '--etc' then fStartParam:= prEtc
  38.     else if ParamStr(1) = '--winner' then fStartParam:= prWinner  { <--- HERE }
  39.     else fStartParam:= prNone;
  40.   end;
  41.   WriteStr(ls,fStartParam); { just to visualize to you }
  42.   stbInfo.SimpleText:= 'Start param = ' + ls; { just to visualize to you }
  43. end;
  44.  
  45. end.
  46.  
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Re: Force parameters of my application
« Reply #7 on: March 18, 2025, 06:56:37 pm »
Thanks a lot, my friend. I'll check it out.
I didn't find the .pas file in the "Archive.zip" attachment.
I love desktop software
https://www.ericksystem.com

cdbc

  • Hero Member
  • *****
  • Posts: 2064
    • http://www.cdbc.dk
Re: Force parameters of my application
« Reply #8 on: March 18, 2025, 07:01:30 pm »
Hi
Ooooouuupppsss, my bad, sorry.
Seems I didn't get it into the zip  %)
Well, the listing is the full pas file...
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Ericktux

  • Sr. Member
  • ****
  • Posts: 377
    • ericksystem software
Re: Force parameters of my application
« Reply #9 on: March 19, 2025, 02:54:56 am »
Hi friend, I've tested the code and it compiles fine, but how can I get it to appear in the process list like this:
Code: Pascal  [Select][+][-]
  1. application1.exe --winner
because it only appears like this in the processes
Code: Pascal  [Select][+][-]
  1. application1.exe
Please help.  :(
I love desktop software
https://www.ericksystem.com

TRon

  • Hero Member
  • *****
  • Posts: 4260
Re: Force parameters of my application
« Reply #10 on: March 19, 2025, 03:02:47 am »
because it only appears like this in the processes
Impossible to accomplish what you want unless the application executes itself again (with the correct parameters).
Today is tomorrow's yesterday.

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: Force parameters of my application
« Reply #11 on: March 19, 2025, 08:42:05 am »
Create a Desktop-Link and append your Parameter there....
If User starts from anywhere else (No Parameters whatsoever) then ShowMessage "Ooops! Use the damn Desktop-Link"

And since when are Parameters shown in the Processlist? Did i miss something?
« Last Edit: March 19, 2025, 08:55:41 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

cdbc

  • Hero Member
  • *****
  • Posts: 2064
    • http://www.cdbc.dk
Re: Force parameters of my application
« Reply #12 on: March 19, 2025, 08:52:00 am »
Hmmmm
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

tetrastes

  • Hero Member
  • *****
  • Posts: 640
Re: Force parameters of my application
« Reply #13 on: March 19, 2025, 09:01:55 am »
And since when are Parameters shown in the Processlist? Did i miss something?
You did.

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: Force parameters of my application
« Reply #14 on: March 19, 2025, 09:17:56 am »
And since when are Parameters shown in the Processlist? Did i miss something?
You did.
OK, thx. Never noticed it
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018