Beranda > Delphi > Open documents and URLs in their associated applications

Open documents and URLs in their associated applications

If you like how Windows Explorer and File Manager lets you open documents just by double clicking on them, without opening the associated program first, here’s how to achieve similar functionality from your Delphi program:

program ShellExe;

uses
  WinTypes, ShellAPI;

procedure OpenObject(sObjectPath: string);
begin
  ShellExecute(0, nil, PChar( sObjectPath ), nil, nil, SW_NORMAL);
end;

begin
  OpenObject('c:\my_docs\report.txt');
end.

Now you can open any type of document from your program without knowing which program is associated with it.

Don’t forget that web site addresses and other URLs also have programs associated with them. So, if you want to open the default browser to a specific URL, simply call OpenObject() with the absolute URL as follows:

OpenObject('http://www.chami.com/tips/');

You can also use the same function to run executable programs, for example:

OpenObject('notepad.exe');
To run programs and wait until they have completed see “Execute a program and wait until it is done“.
Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: