Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1440

Delphi Basics : FindCmdLineSwitch command07

$
0
0

Since I keep forgetting about this, and there is the Embarcadero documentation for it has had no examples added in Delphi 2007 or later: [WayBack] Delphi Basics : FindCmdLineSwitch command

Example code : Saerch the program parameters for 3 switches
begin
// Before running this code, use the Run/parameters menu option
// to set the following command line parameters : /def abc /ghi
ShowMessage(CmdLine);     // Show the execution command + parameters

// How many parameters were passed?
ShowMessage(‘There are ‘+IntToStr(ParamCount)+’ parameters’);

// Scan for parm1, parm2 and parm3 parameters
if FindCmdLineSwitch(‘abc’)
then ShowMessage(‘abc found’)
else ShowMessage(‘abc NOT found’);

if FindCmdLineSwitch(‘def’)
then ShowMessage(‘def found’)
else ShowMessage(‘def NOT found’);

if FindCmdLineSwitch(‘ghi’)
then ShowMessage(‘ghi found’)
else ShowMessage(‘ghi NOT found’);
end;
Show full unit code
   “C:\Program files\Borland\Delphi7\Projects\Project1.exe” /def abc /ghi
There are 3 parameters
abc NOT found
def found
ghi found

Related: [WayBack] delphi – How to read value of ParamStr with different deliminators? – Stack Overflow

Unchanged Embarcadero Delphi 2007 documentation:

For comparison, the Delphi 10.2 Rio documentation:

The really odd thing? The really versatile TCommandParser class got ditched after Delphi XE6: On the Delphi TCommandParser class for parsing command-lines and arguments (via: Suggestions for how to define command line parameters – Stack Overflow).

–jeroen


Viewing all articles
Browse latest Browse all 1440

Trending Articles