Solved

Pass Selected Item to CreateProcess

Posted on 2002-07-20
3
336 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 73
delphi parse string to params 3 122
How to load 2 images in same column in Delphi 2 45
firemonkey keyboard covers the controls 1 25
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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