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
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  SysUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

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;
 
end.
Hide 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 - 2017. All rights reserved.  |  Home Page