Board index » delphi » How to execute file in filelistbox

How to execute file in filelistbox

Hello

I have one FileListBox in a Form. What I want is that when I double click
any file in that Box, the application needed for that file will  be automatic
run and open that file (like in a Windows Explorer).

Could you please help me how to do that
Thank you for help
Nhuyen

http://www.zfree.co.nz

 

Re:How to execute file in filelistbox


Example:

uses
  ShellAPI;

procedure TForm1.FileListBox1DblClick(Sender: TObject);
begin
  ShellExecute(Application.Handle, 'open', PChar(FileListBox1.FileName),
nil, nil, SW_SHOWNORMAL);
end;

ps. If you want a file listbox with Win9x look try the components on
http://home.t-online.de/home/ingo.eckel/d4comp.htm.

"Nhuyen" <sonphu...@zfree.co.nz> schreef in bericht
news:3b4a56f6@zfree.co.nz...

Quote

> Hello

> I have one FileListBox in a Form. What I want is that when I double click
> any file in that Box, the application needed for that file will  be
automatic
> run and open that file (like in a Windows Explorer).

> Could you please help me how to do that
> Thank you for help
> Nhuyen

> http://www.zfree.co.nz

Re:How to execute file in filelistbox


The message <3b4a5...@zfree.co.nz>
  from  "Nhuyen" <sonphu...@zfree.co.nz> contains these words:

Quote
> Hello
> I have one FileListBox in a Form. What I want is that when I double click
> any file in that Box, the application needed for that file will  be automatic
> run and open that file (like in a Windows Explorer).
> Could you please help me how to do that
> Thank you for help
> Nhuyen
> http://www.zfree.co.nz

Lookup Shellexecute in the win32 help. Below is a wrapper
I use to convert all the pchars to strings, Here is how
you would call it:

  ExecuteFile(Filelistbox1.FileName,'','',SW_SHOW);

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)

----------------------------------------------------------
{==============
 Execute File
 ==============}
function ExecuteFile(const FileName, Params, DefaultDir: string;
                           ShowCmd: Integer): THandle;
begin
    Result := ShellExecute(Application.Handle,nil,
    Pchar(FileName),Pchar(Params), Pchar(defaultDir), ShowCmd);
end;

Re:How to execute file in filelistbox


In article <3b4a5...@zfree.co.nz>, sonphu...@zfree.co.nz says...

Quote

> Hello

> I have one FileListBox in a Form. What I want is that when I double click
> any file in that Box, the application needed for that file will  be automatic
> run and open that file (like in a Windows Explorer).

> Could you please help me how to do that
> Thank you for help
> Nhuyen

> http://www.zfree.co.nz

On DoubleClick:
(code is from head, might be useful to look at help for syntax, but way
is this)

fn:=PChar(FileListBox1.items[FileListBox1.selected]);
ShellExecute(handle,'open',fn,nil,nil,SW_SHOWNORMAL);

Other Threads