Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

command line parameters

Posted on 1998-12-06
4
Medium Priority
?
170 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

877 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