|
- unit pdfopenform;
- {$mode objfpc}{$H+}
- interface
- uses
-   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
-   StdCtrls;
- type
-   { TForm1 }
-   TForm1 = class(TForm)
-     TProcessButton: TButton;
-     OpenURLButton: TButton;
-     OpenDocumentButton: TButton;
-     PDFChooser: TFileNameEdit;
-     Label1: TLabel;
-     procedure OpenDocumentButtonClick(Sender: TObject);
-     procedure OpenURLButtonClick(Sender: TObject);
-     procedure TProcessButtonClick(Sender: TObject);
-   private
-     { private declarations }
-   public
-     { public declarations }
-   end;
- var
-   Form1: TForm1;
- implementation
- uses process {for TProcess}, lclintf {for OpenDocument, OpenURL};
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.TProcessButtonClick(Sender: TObject);
- var
-   AProcess: TProcess;
- begin
-   AProcess:=TProcess.Create(Nil);
-   try
-     // Executable & Parameters instead of CommandLine: no problems with quotes
-     AProcess.Executable:='explorer.exe';
-     AProcess.Parameters.Add(PDFChooser.FileName);
-     AProcess.Options := AProcess.Options + [poWaitOnExit];
-     AProcess.Execute;
-   finally
-     AProcess.Free;
-   end;
- end;
- procedure TForm1.OpenDocumentButtonClick(Sender: TObject);
- begin
-   //Opendocument opens a document with the default application associated with it in the system
-   if OpenDocument(PDFChooser.FileName)=false then ShowMessage('OpenDocument method failed.');
- end;
- procedure TForm1.OpenURLButtonClick(Sender: TObject);
- begin
-   // Opens a given URL with the default browser
-   // I wouldn't use this one because it's an extra redirection step and the user may not
-   // have a pdf plugin etc
-   if OpenURL('file://'+PDFChooser.FileName)=false then ShowMessage('OpenURL method failed.');
- end;
- end.
复制代码
完整项目代码下载 |
|