Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console application - how to send parameters ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I've out together a simple console application using Delphi.
Is there any way in which I can start such a program and pass it parameters.
What I'm currently doing at the moment is to have various prompts on start of the console application such that the variables are set up.
Ideally I want to run the console application with as little user intervention as possible.
Can I start the console application and pass parameters as I do so ?
Any help would be appreciated.
Thanks in advance
Steve
 
hi,

Yes you can use ParamCount.

The following example beeps once for each “beep” passed in on the command line. The example terminates the application if “exit” is passed in on the command line.

procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
for i := 1 to ParamCount do
begin
if LowerCase(ParamStr(i)) = 'beep' then
Beep
else if LowerCase(ParamStr(i)) = 'exit' then
Application.Terminate;
end;
end;

So you run the apps like

project1 beep nothing beep exit

Steph [Bigglasses]
 
I'm looking at a non-visual application - your code is for a form - is the principle the same here ? I would imagine that it differs in this case.
Thanks again
Steve
 
hi,

You are right the code is for use with a form.
The same thing can be achieved with an init procedure in your apps.

Steph [Bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top