Solved

Accepting parms in an exe.

Posted on 2000-04-11
6
152 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now