Solved

Accepting parms in an exe.

Posted on 2000-04-11
6
156 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send message from delphi to whatsapp, is it possible? 3 1,637
Delphi selector screen 2 84
LAN or WAN ? 11 95
how to update exe applicatio from internet ? 6 85
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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