Link to home
Start Free TrialLog in
Avatar of vhabaygiurbm
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(StartInfo);
 StartInfo.dwFlags:=STARTF_USESHOWWINDOW;
 StartInfo.wShowWindow:=ShowMode;
 if AppName<>'' then CreateProcess(PChar(APPName), 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(ProcInfo.hProcess, INFINITE);
 GetExitCodeProcess(ProcInfo.hProcess, Result);
finally
 CloseHandle(ProcInfo.hProcess);
 CloseHandle(ProcInfo.hThread );
end;
end;

************************************************
************************************************
procedure TForm1.Button1Click(Sender: TObject);
var
 res: integer;
begin
 res := ExecApplication('pptview\ppview32.exe'+pptfile,'',SW_SHOWNORMAL,true);
 //showmessage(pptfile);
 end;
*************************************************
*************************************************

procedure TForm1.FileListBoxEx1Click(Sender: TObject);

begin
 pptfile:=Filelistboxex1.Items[filelistboxex1.itemIndex];
 Button2.Enabled:=False;
 Button1.Enabled:=True;
end;

procedure TForm1.FileListBoxEx2Click(Sender: TObject);
begin
Button1.Enabled:=False;
Button2.Enabled:=True;
end;

end.
Avatar of marcoszorrilla
marcoszorrilla

For quotes you can try with:
QuotedStr(pptFile);

Best Rergards
Marcos.
ASKER CERTIFIED SOLUTION
Avatar of Lee_Nover
Lee_Nover

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vhabaygiurbm

ASKER

Thank you much! That worked for me...

Thanks again,
MG