Solved

Accepting command arguments

Posted on 2000-02-19
9
139 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
[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
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
Independent Software Vendors: 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 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: 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.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
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…

726 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