Solved

command line parameters

Posted on 1998-12-06
4
166 Views
Last Modified: 2010-04-04
How do I make my delphi programs accept command line parameters? (e.g. myprogram.exe /start /f -d)
0
Comment
Question by:PsychoFox
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 1349616
Use the functions ParamStr(x) and ParamCount

In the FormCreate method, do something like:

Procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
    S: String;
begin
   For i := 0 to ParamCount-1 do
      S := ParamStr(i)
end;

And thats about it!

Let me know if you need more info!

Stu.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1349617
hi PsychoFox, StuartJohnsen,

in addition to starts answer,

stuart:
you loose the last parameter,

the line
 For i := 0 to ParamCount-1 do
should be
 For i := 0 to ParamCount do

ParamStr(0) holds path and exeName of the program

PsychoFox

you should do what you want with the parameters

var
  ExeName : String;
  ToStart : Boolean;
  FOption : String;

Procedure TForm1.FormCreate(Sender: TObject);
    var I: Integer;
        S: String;
    begin
       For i := 0 to ParamCount do
       begin
          If i = 0 then ExeName := ParamStr(0)
          else
          begin
             If ParamStr(i) = '/Start' then ToStart := True
             else
                If ParamStr(i) = '/f' and i+1 <= Paramcount then FOption := ParamStr(i+1)
                else
                  { and so on ... }
          end;

    end;


meikl
0
 

Author Comment

by:PsychoFox
ID: 1349618
Also thanx to kretzschmar!
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1349619
Thanks for pointing that out.  I didnt have Delphi loaded on the machine that I was answering that from and just did it from memory :)

Glad to be able to help you.

Stu.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Controlled Assessment GCSE - desperate help needed 4 102
Create a path if not exists 7 90
Delphi Yen format 3 45
Multi-layered image in FireMonkey 9 49
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question