We help IT Professionals succeed at work.

How to Passing and Received parameter outside the Delphi EXE file?

chungee
chungee asked
on
Medium Priority
1,660 Views
Last Modified: 2010-04-06
I got a main Delphi Application.
When calling other sub Delphi Application, i need to
passing some parameter to other .EXE(Delphi .EXE file).

Then the sub Delphi Application have to get the parameter which i passing from the main Delphi EXE application.

How to do?
I am so urgent.
Comment
Watch Question

Commented:

{ Open a file or starts a programm (without parameters) }
procedure OpenFile(filename : string);
var c : array[0..800] of char;
begin
 StrPCopy(c,filename);
 ShellExecute(Application.Handle,'open',c, nil, nil, SW_NORMAL);
end;

{ Starts a programm with commandline parameters }
procedure OpenProgram(prog, params : string);
var c,p : array[0..800] of char;
begin
 StrPCopy(c,prog);
 StrPCopy(p,params);
 ShellExecute(Application.Handle,'open',c,p, nil, SW_NORMAL);
end;

for more info,
http://www.swissdelphicenter.ch/en/showcode.php?id=455

Commented:
To retrieve the parameters your app was started with look at the paramStr & paramCount functions. For example, every command line must have, at least, the name of the app that was executed so if you put this in your main form's OnCreate handler:

procedure TForm1.FormCreate(Sender: TObject);
begin
     caption := intToStr(paramCount)+','+paramStr(0);
end;

The caption of the form will give the number of parameters (0 just means there's the app name with no parameter) & the application fileName.

GL
Mike
Commented:
Calling application:

uses ..., ShellAPI;

procedure StartSub(prog, params: string);
begin
  ShellExecute(Application.Handle, nil, pchar(prog), pchar(params), nil, SW_SHOWNORMAL);
end;

Sub application:

program subApplication;

uses
  ...,
  SysUtils,
  Windows,
  Dialogs;

var i1 : integer;
begin
  for i1 := 1 to ParamCount do
    ShowMessage('Parameter No. ' + IntToStr(i1) + ': "' + ParamStr(i1) + '"');
  Application.Initialize;
  Application.CreateForm(...);
  ...
  Application.Run;
end.

Regards, Madshi.

Commented:
Take a look at this ideea .
Sorry if I understand wrong your need .

{
The following code is used to
insert a character into another
application - Notepad
}
 
procedure TForm1.Button1Click(Sender: TObject);
var g,d:integer;
begin
 {Find the main window of the Application}
 g:=FindWindow('Notepad',nil);                                // Your's second application
 {Find the window of the application's text box}
 d:=ChildWindowFromPoint(g,point(50,50));
 {Now send it a character!!}
 SendMessage(d,WM_CHAR,Ord('A'),0);               // your value
end;

Commented:
Or... to share data between two applications by means of a memory mapped file with GlobalAtom.

Take alook at http://alphomega.developpez.com/EchangeVal/ and download CodeSource for D5 - on page bottom

Author

Commented:
Thanks. This code is really helping me.Really!