Solved

Accepting parms in an exe.

Posted on 2000-04-11
6
160 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 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
Technology Partners: 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

617 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