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

x
?
Solved

Accepting parms in an exe.

Posted on 2000-04-11
6
Medium Priority
?
161 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
[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
6 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

704 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