Solved

Pass Selected Item to CreateProcess

Posted on 2002-07-20
3
339 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
ID: 7166794
For quotes you can try with:
QuotedStr(pptFile);

Best Rergards
Marcos.
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 50 total points
ID: 7166803
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
ID: 7167687
Thank you much! That worked for me...

Thanks again,
MG
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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