Hola
Para conectar un programa a otro, estando en la misma carpeta o directorio.
Esta es una muestra de un programita completo:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
type
EExecAppError = class(Exception);
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
function ExecuteApp(AppName, Params: string): TProcessInformation;
procedure Launch(AppName, Params: string);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure appmessage(var msg:tmsg;var handled:boolean);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function SysErrorMessageParam(ErrorCode: Integer; Param: string): string;
var
Len: Integer;
Buffer: array[0..255] of Char;
ArgArray: array[1..1] of PChar;
begin
ArgArray[1] := PChar(Param);
Len := FormatMessage(Format_Message_From_System or
Format_Message_Argument_Array, nil, ErrorCode, 0, Buffer,
SizeOf(Buffer), @ArgArray);
while (Len > 0) and (Buffer[Len - 1] in [#0..#32, '.']) do Dec(Len);
SetString(Result, Buffer, Len);
end;
function TForm1.ExecuteApp(AppName, Params: string): TProcessInformation;
var
SI: TStartupInfo;
PI: TProcessInformation;
begin
FillChar(SI, SizeOf(SI), 0);
with SI do
begin
cb := SizeOf(TStartupInfo);
dwFlags := StartF_UseShowWindow;
wShowWindow := sw_ShowNormal;
end;
if not CreateProcess(nil, PChar(AppName + ' ' + Params), nil,
nil, False, 0, nil, nil, SI, PI) then
raise EExecAppError.Create(SysErrorMessageParam(GetLastError, AppName));
Result := PI;
end;
procedure TForm1.Launch(AppName, Params: string);
begin
ExecuteApp(AppName, Params);
end;
procedure TForm1.appmessage(var msg:tmsg; var handled:boolean);
begin
if (msg.message=wm_syscommand) and (msg.wparam=sc_screensave)
then handled:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Launch('Project2','');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.onmessage:=appmessage;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
end.
Saludos