Solved

Pass Selected Item to CreateProcess

Posted on 2002-07-20
3
331 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:vhabaygiurbm
3 Comments
 
LVL 3

Expert Comment

by:marcoszorrilla
Comment Utility
For quotes you can try with:
QuotedStr(pptFile);

Best Rergards
Marcos.
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 50 total points
Comment Utility
you should use the filename as the CMDLine
also the first parameter in the CMDLine is IGNORED !!!
if you want to pass a filename then do it like:
PChar(Format('MyAppRules "%s"', [FileName])
this is how I have it and it works fine:

np:=GetNextPort;
     // CreateProcess uses items after the first white space as parameters !!!
     param:=Format('VideoServer %d "%s" %d "%s"', [np, sp, Handle, txtServerName.Text]);
     ok:=CreateProcess('VideoServer.exe', PChar(param), nil,
       nil, true, NORMAL_PRIORITY_CLASS, nil, PChar(sp), si, pi);


dunno about the FileListBox, but do you get a full path of the file at all ?
shouldn't it be smth like : FileName:=FileListBoxex1.Directory + '\' + Filelistboxex1.Items[filelistboxex1.itemIndex];
0
 

Author Comment

by:vhabaygiurbm
Comment Utility
Thank you much! That worked for me...

Thanks again,
MG
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

10 Experts available now in Live!

Get 1:1 Help Now