Solved

Accepting parms in an exe.

Posted on 2000-04-11
6
155 Views
Last Modified: 2010-04-04

How can I accept parameters (for example 4 integers and a string) in my exe when its called?  I want the exe to be able to use the parameters in the main form when the form loads.  D3.
 
              Thank you
0
Comment
Question by:jexd99
6 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 50 total points
ID: 2706552
use ParamStr(1), ParamStr(2) ...

for example write this code in form's OnCreate event:

var
  i: Integer;
begin
  for i:= 1 to ParamCount do
    Memo1.Lines.Add(ParamStr(i));
end;

This will display all parameters in a Memo

If you need any help please tell me
Motaz
www.geocities.com/motaz1
0
 

Expert Comment

by:ShadowFax
ID: 2707033
Or try this:

var
  MyInt1, MyInt2, MyInt3, MyInt4:   Integer ;
  MyString: String ;

procedure MyForm.Create(Sender: TObject);
begin
// check if there are the required params
  if ParamCount = 6 then
  begin
// populate your variables
    MyInt1 := StrToInt(ParamStr(1)) ;
    MyInt2 := StrToInt(ParamStr(2)) ;
    MyInt3 := StrToInt(ParamStr(3)) ;
    MyInt4 := StrToInt(ParamStr(4)) ;
    MyString := ParamStr(5) ;
  end
  else
// can close the app which would prevent the app from being run without the run params, or you can just ignore and put default values into your variables
    Application.Terminate ;
end;

HTH

Gavin
0
 

Expert Comment

by:ShadowFax
ID: 2707038
Remember...

ParamStr(0) hold your application Path and and name(ie. c:\program files\MyApp.exe)
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Expert Comment

by:nrico
ID: 2707305
And now for a little explanation of this code :-) :

Your program can get passed command-line parameters, these are separated by spaces. To make a string with spaces in it appear as a single parameter, put "" around it.
You can access the number of parameters passed through the ParamCount function, and you can get the separate parameters as strings using ParamCount(<Number>);
To convert these to integers, you can use the StrToInt() function.
0
 
LVL 1

Expert Comment

by:flooder
ID: 2711025
You can use ParamStr(x) and
ParamCount
Remember as said above space count as seperate parameters.
So long file names send by explorer will be a lot of paramters.
Secondly all parameters passes are strings so you would have to know that for eg the first parameter is always a integer. Or what you can do is send a code with each parameter that tells your program what the type should be.
eg
I=integer  I234
$=String   $Hullo_World
0
 

Author Comment

by:jexd99
ID: 2714018
Thank you all for your input. The answers were all very informative, this is slick! :)  (I have to give the pts to the one who answered first, as the answers were all equally good).

          Thanks again  
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
Delphi : could not find program, '...exe' 2 171
QRReport  TQrmemo vertical stretching 1 46
LAN or WAN ? 11 90
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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