Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accepting command arguments

Posted on 2000-02-19
9
Medium Priority
?
141 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

597 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