Solved

Accepting command arguments

Posted on 2000-02-19
9
131 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

21 Experts available now in Live!

Get 1:1 Help Now