DelphiBasics
ParamStr
Function
Returns one of the parameters used to run the current program System unit
 function ParamStr ( ParmIndex : Integer ) : string;
Description
The ParamStr function returns one of the parameters from the command line used to invoke the current program.
 
The ParamIndex parameter determines which parameter is returned:
 
0 : The execution drive/path/program 1 : Return the 1st parameter 2 : Return the 2nd parameter ...
 
If there is no parameter value for the given index,an empty string is returned.
 
Notes
The related FindCmdLineSwitch function can be used to check for the presence of parameters, as starting with a control character, such as - or /.
Related commands
CmdLine Holds the execution text used to start the current program
FindCmdLineSwitch Determine whether a certain parameter switch was passed
ParamCount Gives the number of parameters passed to 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

  // 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
   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