ObjectPascal
FindCmdLineSwitch
Function
Determine whether a certain parameter switch was passed SysUtils unit
1  function FindCmdLineSwitch ( const SwitchValue : string ) : Boolean;
2  function FindCmdLineSwitch ( const SwitchValue : string; IgnoreCase : Boolean ) : Boolean;
3  function FindCmdLineSwitch ( const SwitchValue : string; SwitchChars : TSysCharSet; IgnoreCase : Boolean ) : Boolean;
Description
The FindCmdLineSwitch function scans the command line (program + parms used to invoke the current program) for a given parameter switch. It saves the coder from this parsing activity.
 
Switches are optional parameters prefixed by :
 
- / for Windows - for Linux
 
but may be specified in SwitchChars in Version 3 of the function.
 
The SwitchValue follows this prefix character, and is the value scanned for in the command line by this function.
 
The IgnoreCase parameter in Versions 2, 3 of the function determines whether the scan ignores the case of the SwitchValue. The default is True
Related commands
CmdLine Holds the execution text used to start the current program
ParamCount Gives the number of parameters passed to the current program
ParamStr Returns one of the parameters used to run the current program
TSysCharSet Characters used by supplied string parsing functions
 
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?
  WriteLn('There are '+IntToStr(ParamCount)+' parameters');

  // Scan for parm1, parm2 and parm3 parameters
  if FindCmdLineSwitch('abc')
  then WriteLn('abc found')
  else WriteLn('abc NOT found');

  if FindCmdLineSwitch('def')
  then WriteLn('def found')
  else WriteLn('def NOT found');

  if FindCmdLineSwitch('ghi')
  then WriteLn('ghi found')
  else WriteLn('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