I want to know how to do either:
On a button click, open a PDF file from a directory.
View a PDF file on the Form.
I want to know how to do either:
On a button click, open a PDF file from a directory.
View a PDF file on the Form.
You don't need all of the jumping-through hoops you're doing. Windows will find the application associated with PDF files for you.
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
Ret: DWord;
begin
s := 'C:\MyFiles\MyFile.pdf';
Ret := ShellExecute(Handle, nil, PChar(s), nil, nil, SW_SHOW);
if Ret < 32 then
ShowMessage(SysErrorMessage(GetLastError));
end;
Note: Normally you should never call a WinAPI function without checking the return value. In this case, you'll know if it didn't work because the PDF won't open.
To embed a PDF, the first 2 thoughts that come to mind would be
1) search for a COM object that supports PDFs - a quick search produced this: http://www.biopdf.com/guide/com_interface.php, but there appear to be others.
2) Worst case you can embed a web panel that has HTML code along these lines in it:
<object data="test.pdf" type="application/pdf" width="500" height="300">
alt : <a href="test.pdf">test.pdf</a>
</object>
thanks for the answers but I eventually got to it (Haven't been using Delphi for a couple of years now, forgot about the uses).
This was how: "On a button click, open a PDF file from a directory."
uses shellApi;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open', 'C:\pathwaytopdf.pdf', nil, nil, SW_SHOWNORMAL);
end;
end.
Thank you for the answers.