Solved

Pass Selected Item to CreateProcess

Posted on 2002-07-20
3
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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