DelphiBasics
ParamCount
Function
Gives the number of parameters passed to the current program System unit
 function ParamCount : Integer;
Description
The ParamCount function gives the number of command line parameters used to invoke the current executable.
Notes
The related ParamStr function returns these parameters as index values 1, 2 etc.
Related commands
CmdLine Holds the execution text used to start the current program
FindCmdLineSwitch Determine whether a certain parameter switch was passed
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 command line parameters
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