Name

ParamStr Function

Syntax

function ParamStr(Number: Integer): string;

Description

The ParamStr function returns the Numberth command-line parameter. ParamStr is a real function.

Tips and Tricks

  • Parameter number zero is the application pathname.

  • Parameters are numbered from 1 to ParamCount. If Number is invalid, ParamStr returns an empty string.

  • When breaking a command line into parameters, Delphi uses white space characters as separators. Use double quotes around text that contains space characters to include the spaces as part of the parameter (e.g., long filenames).

  • To look for command-line switches, call the FindCmdLineSwitch function from the SysUtils unit.

Example

program Echo;
// Echo command-line arguments, separated by spaces.
{$AppType Console}
var
  I: Integer;
begin
  if ParamCount > 0 then
    Write(ParamStr(1));
  for I := 2 to ParamCount do
    Write(' ', ParamStr(I));
  WriteLn;
end.

See Also

CmdLine Variable, ParamCount Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.