Solved

command line parameters

Posted on 1998-12-06
4
161 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

14 Experts available now in Live!

Get 1:1 Help Now