Important alert: (current site time 7/16/2013 5:54:24 AM EDT)
 

article

ParamCount and ParamStr

Email
Submitted on: 7/9/2000 4:44:10 PM
By:  
Level: Beginner
User Rating: Unrated
Compatibility: Delphi 5, Delphi 4, Pre Delphi 4
Views: 6084
 
     How to get the paramaters passed into your program from the command line.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

rocedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
begin
    for I := 0 to ParamCount do
    Label1.Caption := ParamStr(I);
    Label2.Caption := IntToStr(ParamCount); 
end;

If you type 'Project1 /p' (without the quotes in DOS or put it in the programs Properties -> Shortcut -> Target, like this "C:\Delphi 3\BIN\examples\Project1.exe" /p)

This is what you get:

Label1 = /p
Label2 = 1

This is one of the Delphi help files examples:

procedure TForm1.Button2Click(Sender: TObject);
var I : Word; Y : Integer;
begin
    Y := 10;
    for I := 0 to ParamCount do 
  begin
      Canvas.TextOut(5, Y, ParamStr(I));
      Y := Y + Canvas.TextHeight(ParamStr(I)) + 5;
  end;

And this is what you get from this example:

C:\Delphi 3\bin\examples\Project1.exe


Other 31 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/21/2005 12:40:14 AMAyman Fouad

but my friend if param have any space it's will be wrong back for example:
C:\me and me\project1.exe

back
C:\me
and
me\project1.exe

i think it's bad if i want to run this exe can you help me for that
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.