Lenguaje de programación Borland Delphi
Os mostramos el código fuente necesario para abrir cualquier fichero con su apliación asociada. Se necesitará un formulario, un botón (TButton) y un cuadro de edición (TEdit):
unit Unit1;
{ Have some fun with the Shell" by: Wendell Jones
have your Delphi apps use the Shell32.DLL }
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
cmd : String;
begin
Button1.Enabled := false;
cmd := 'rundll32.exe shell32.dll,OpenAs_RunDLL ' + Edit1.text;
if WinExec(@cmd[1],0)<32 then
MessageDlg('No se ha podido abrir el fichero '+
Format('%s',[cmd]),mtError,[mbok],0);
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
If Edit1.text <> '' then
Button1.Enabled := true
else
Button1.Enabled := false;
end;
end.
Publicado el: 2004-03-06