Solved

command line parameters

Posted on 1998-12-06
4
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
Also thanx to kretzschmar!
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now