Posted on 10,487 Comments

How to Create a Console Application that Accepts Command-Line parameters in Delphi

Steps: In the Delphi IDE, choose File/New/Console Application. Then write

program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;

begin
// Following code you have to write

if ParamCount = 0 then
begin
Writeln(‘No parameters passed.’);
end;
if ParamCount = 1 then
begin
Writeln(‘One Parameter passed!’);
Writeln(ParamStr(1));
end;
if ParamCount = 2 then

begin
Writeln(‘Two Parameters passed!’);
Writeln(ParamStr(1));
Writeln(ParamStr(2));
end;
if ParamCount > 2 then
Writeln(‘More than Two Parameters passed!’);
end.

Compile.

Run CMD and go to directory where you saved the project

In Command Prompt

c:\TestConsole\Project1 “hello world”

One parameter passed

hello world

c:\TestConsole\Project1 “hello” “world”

Two Parameter passed

hello

world