unit UShellExecute;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button3: TButton;
    OpenDialog1: TOpenDialog;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if OpenDialog1.Execute
  then begin
    if ShellExecute(Handle, 'open', PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL)
      <= 32
    then ShellExecute(Handle, 'edit', PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL);
   Button3.Enabled := true;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 ShellExecute(Handle, 'print', PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if OpenDialog1.Execute
  then begin
   if ShellExecute(Handle, 'edit', PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL)
      <= 32
    then ShellExecute(Handle, nil, PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL);
   Button3.Enabled := true;
  end;
end;

end.
