vhabaygiurbm
asked on
Pass Selected Item to CreateProcess
HELP!
Below I am using a filelistboxex and selecting an item from it, I try and pass this filename to the exe and can't get it right...also I will have instances for the need to put quotes around my filename picked from the listbox because of spaces...
Any help will be appreciated!
Thanks
__________________________ __________ __________ __________
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, jpeg, ExtCtrls, CoolCtrls, CoolPolygons, CoolTools,
Buttons, FileCtrl, FlCtrlEx, EllipsLabel, Shader;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
FileListBoxEx1: TFileListBoxEx;
FileListBoxEx2: TFileListBoxEx;
Shader1: TShader;
procedure Button1Click(Sender: TObject);
procedure FileListBoxEx1Click(Sender : TObject);
procedure FileListBoxEx2Click(Sender : TObject);
private
{ Private declarations }
public
pptfile: string;
pptfilefix: string;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
var StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
try
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb:=SizeOf(Start Info);
StartInfo.dwFlags:=STARTF_ USESHOWWIN DOW;
StartInfo.wShowWindow:=Sho wMode;
if AppName<>'' then CreateProcess(PChar(APPNam e), PChar(CmdLine), nil, nil, False, 0,
nil, nil, StartInfo, ProcInfo)
else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0,
nil, nil, StartInfo, ProcInfo);
if WaitToExit then WaitForSingleObject(ProcIn fo.hProces s, INFINITE);
GetExitCodeProcess(ProcInf o.hProcess , Result);
finally
CloseHandle(ProcInfo.hProc ess);
CloseHandle(ProcInfo.hThre ad );
end;
end;
************************** ********** ********** **
************************** ********** ********** **
procedure TForm1.Button1Click(Sender : TObject);
var
res: integer;
begin
res := ExecApplication('pptview\p pview32.ex e'+pptfile ,'',SW_SHO WNORMAL,tr ue);
//showmessage(pptfile);
end;
************************** ********** ********** ***
************************** ********** ********** ***
procedure TForm1.FileListBoxEx1Click (Sender: TObject);
begin
pptfile:=Filelistboxex1.It ems[fileli stboxex1.i temIndex];
Button2.Enabled:=False;
Button1.Enabled:=True;
end;
procedure TForm1.FileListBoxEx2Click (Sender: TObject);
begin
Button1.Enabled:=False;
Button2.Enabled:=True;
end;
end.
Below I am using a filelistboxex and selecting an item from it, I try and pass this filename to the exe and can't get it right...also I will have instances for the need to put quotes around my filename picked from the listbox because of spaces...
Any help will be appreciated!
Thanks
__________________________
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, jpeg, ExtCtrls, CoolCtrls, CoolPolygons, CoolTools,
Buttons, FileCtrl, FlCtrlEx, EllipsLabel, Shader;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
FileListBoxEx1: TFileListBoxEx;
FileListBoxEx2: TFileListBoxEx;
Shader1: TShader;
procedure Button1Click(Sender: TObject);
procedure FileListBoxEx1Click(Sender
procedure FileListBoxEx2Click(Sender
private
{ Private declarations }
public
pptfile: string;
pptfilefix: string;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
var StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
try
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb:=SizeOf(Start
StartInfo.dwFlags:=STARTF_
StartInfo.wShowWindow:=Sho
if AppName<>'' then CreateProcess(PChar(APPNam
nil, nil, StartInfo, ProcInfo)
else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0,
nil, nil, StartInfo, ProcInfo);
if WaitToExit then WaitForSingleObject(ProcIn
GetExitCodeProcess(ProcInf
finally
CloseHandle(ProcInfo.hProc
CloseHandle(ProcInfo.hThre
end;
end;
**************************
**************************
procedure TForm1.Button1Click(Sender
var
res: integer;
begin
res := ExecApplication('pptview\p
//showmessage(pptfile);
end;
**************************
**************************
procedure TForm1.FileListBoxEx1Click
begin
pptfile:=Filelistboxex1.It
Button2.Enabled:=False;
Button1.Enabled:=True;
end;
procedure TForm1.FileListBoxEx2Click
begin
Button1.Enabled:=False;
Button2.Enabled:=True;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you much! That worked for me...
Thanks again,
MG
Thanks again,
MG
QuotedStr(pptFile);
Best Rergards
Marcos.