Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

command line parameters

Posted on 1998-12-06
4
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

661 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