DelphiBasics
CmdLine
Variable
Holds the execution text used to start the current program System unit
  var CmdLine : PChar;
Description
The CmdLine variable holds the full drive, path, and file name of the currently executing program, followed by any parameters that were supplied.
 
The drive/path/file part is given mixed case in double quotes, followed by a space and the parameters, in mixed case.
Notes
The related ParamStr function returns the drive/path/file in Upper case.
Related commands
FindCmdLineSwitch Determine whether a certain parameter switch was passed
ParamCount Gives the number of parameters passed to the current program
ParamStr Returns one of the parameters used to run the current program
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
Example code : Display the command line with two parameters passed
var
  cmd : string;
  i : Integer;

begin
  // Before running this code, use the Run/parameters menu option
  // to set the following command line parameters : -parm1 -parm2
  cmd := CmdLine;
  ShowMessage(cmd);     // Show the execution command + parameters

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

  // Show these parameters - note that the 0th parameter is the
  // execution command on Windows
  for i := 0 to ParamCount do
    ShowMessage('Parameter '+IntToStr(i)+' = '+ParamStr(i));
end;
Show full unit code
   "C:\Program files\Borland\Delphi7\Projects\Project1.exe" -parm1 -parm2
   There are 2 parameters
   Parameter 0 = C:\PROGRAM FILES\BORLAND\DELPHI7\PROJECTS\PROJECT1.EXE
   Parameter 1 = -parm1
   Parameter 2 = -parm2
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page