Solved

Accepting command arguments

Posted on 2000-02-19
9
132 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

22 Experts available now in Live!

Get 1:1 Help Now