1 (edited by v_pozidis 2020-11-17 21:01:21)

Topic: Open a pdf file

How can I pressing a button to open a pdf file ?

Re: Open a pdf file

Is this a PDF link saved in a database?

If it is the following code relies on Windows associating file types and will automatically open the correct program.

procedure frmMain_btnOpenPDF_OnClick (Sender: TObject; var Cancel: boolean);
var
  fName :string;
begin
  fName := SQLExecute('SELECT DISTINCT File_Filename FROM SomeTable WHERE id = '+frmMain.tgTable.SQLValue);
  OpenFile(fName); 


Alternatively if you only ever want to open a PDF file then the above becomes



var
  fName :string;
begin
  fName := SQLExecute('SELECT DISTINCT File_Filename FROM SomeTable WHERE id = '+frmMain.tgTable.SQLValue);
  OpenFile(fName,'AcroRD32.exe'); 

If you are not getting the file name from a database link, just substitute the fName :=  with path and file name of the file you want opened.  Obviously you could add in an OpenDialog if you want the user to search for a file or have an edit box for the user to fill out a name etc.

On a clear disk you can seek forever

Re: Open a pdf file

The file is not in the database. It is just a simply pdf file. I like to open it for a reason when i Press a command button

Re: Open a pdf file

Hello v_pozidis

To simply open a file outside of the database , place this code behind a button and its event OnClick


OpenFile ('Z: \ WIP \ WIP.xls');

In this case, Excel will launch and open the WIP.xls file(and you know its path)

To make it more classy, you could use an OpenFile dialog box

JB

5 (edited by blackpearl8534 2020-11-18 17:35:06)

Re: Open a pdf file

Use this on button on click button on click event

Openfile('filename.pdf');