Solved

Accepting command arguments

Posted on 2000-02-19
9
136 Views
Last Modified: 2010-08-05
I want to pass a command from a vb app to a delphi app.

I want to pass a string to my delphi app when it is called.

I need code to store this string as a variable.
0
Comment
Question by:fibdev
9 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2539116
Use ParamStr(i) to get commandline parameter i. ParamStr(0) is the command itself. ParamCount returns the number of parameters, excluding PAramStr(0).
0
 

Expert Comment

by:toesable
ID: 2539355
This is one way

k := Paramcount;
while (i <= k) do
  begin
    argp := ParamStr(i);
    if (argp = '-help') then begin
      ...
    end;
    inc(i);
  end;
0
 

Expert Comment

by:toesable
ID: 2539359
Oh, forgot, in case you don't know, this goes in your dpr file before Application.run statement.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 5

Expert Comment

by:TheNeil
ID: 2539689
Actually toesable it can go anywhere in the application

fibdev - I don't know how you launch another application in VB but from Delphi you'd need to run your application with something like ShellExecute and pass your parameter as a command line parameter. toesable and epsylon have covered how you get the data back OUT but didn't mention how you'd actually get the parameter IN from your VB code. As I said, I don't know VB but the ShellExecute command in Delphi would go something like:

ShellExecute(nil, 'Open', 'Filename.exe', '-help', '', SH_SHOW);

As this is an API call you SHOULD be able to use it from VB

The Neil
0
 
LVL 3

Author Comment

by:fibdev
ID: 2539713
In vb I would be passing the paramater like so:

Dim X   'Variable
Dim aParam As String  ' Variable for the paramter
Dim dApp As String 'Variable for the delphi app to run

aParam = "%1"
dApp = "c:\mydelphiapp.exe"
X = Shell(dApp & " " & aParam, vbHide)
0
 
LVL 3

Accepted Solution

by:
Alisher_N earned 50 total points
ID: 2539747
%1 is a var by itself (used in .BAT files)  ;-)
probably you have to use

aParam = "This_String_needed_for_Delphi_Application"
dApp = "mydelphiapp.exe"
lX = Shell(dApp & " " & aParam, vbHide)

later in mydelphiapp you can get it via

var
   ParamFromVB : String;

begin
   ParamFromVB := ParamStr(1);
  if ParamFromVB ='' then ShowMessage( 'empty command line option' )
else DoMyCoolStuff;
0
 
LVL 3

Author Comment

by:fibdev
ID: 2539785
Alisher,

I've changed my mind on how I want to do this, so ... how do I accept the param from a shell extention?

I want to set paramFrom = %1 {the variable from my shell extention}
var
   ParamFrom : String;

begin
   ParamFrom := ParamStr(1);
  if ParamFrom ='' then ShowMessage( 'empty command line option' )
else DoMyCoolStuff;




0
 

Expert Comment

by:toesable
ID: 2539798
Thankyou theneil.  Didn't know...
0
 
LVL 3

Author Comment

by:fibdev
ID: 2540097
Thanks Alisher,

I used your example, it worked great.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 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…

828 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