Topic: TWebBrowser Container

Hi All,
Some help if anyone has any ideas please.
I have an application that holds information about .pdf files.
When you run the application, if you click in Column 2 (View) the .pdf file is opened in a TWebBrowser container (see screenshot1 in the attachment). 
When you click on a new row, a new .pdf is displayed.
The problem is when there is a row of data with no associated .pdf;  in this case, the previously selected .pdf is still displayed (see screenshot1 in the attachment).
What I am trying to do is clear the TWebBrowser container when there is no associated .pdf but have not had any success so far.
I'm using MVD 6.5 with SQLite and running Windows 10.
Thanks in advance for any help,
Derek.

Post's attachments

Attachment icon pdf document viewer.zip 1.05 mb, 132 downloads since 2024-03-06 

2 (edited by sparrow 2024-03-06 22:20:41)

Re: TWebBrowser Container

Hi Derek,

The simplest solution is to create a blank page (html file) or with an inscription. If the request does not return a name, load a blank page.

procedure Form1_TableGrid1_OnCellClick (Sender: TObject; ACol, ARow: Integer);                                          //** if column2 clicked, then retrieve the relevant .pdf file
begin
  if acol = 2 then
    begin
      vpath := sqlexecute('select doclocation_filename from mydocuments where id = "'+form1.tablegrid1.sqlvalue+'"');
      vweb.navigate(vpath);
      if vpath = '' then vweb.navigate('C:\  . . . \pdf document viewer\documents\empty.html');

    end;
end;

The option of permanently re-creating TWebBrowser is also possible.

Re: TWebBrowser Container

Hi Sparrow,
Everything's working well now.
Thanks for your help.
Derek.

Re: TWebBrowser Container

Hi Derek,


It's even easier

if vpath = '' then vweb.navigate('about:blank');

It also wouldn’t hurt to check for the presence of a file in the directory before opening it.

Re: TWebBrowser Container

Yes, simple and straightforward.
Thanks for the extra information.
Derek.

Re: TWebBrowser Container

Hi Derek,


Thanks for posting useful little utility.
At my end it says "This page can’t be displayed"
Is it my OS as I'm using Win 7

Adam
God... please help me become the person my dog thinks I am.

Re: TWebBrowser Container

Hi Adam,
I wasn't ignoring you ( big_smile ) - I just didn't see your post.  Sorry.
I think the 'page cannot be displayed' message is simply because I was using hard coded links to example documents rather than using relative links.
Obviously you wouldn't usually use 'hard coded' links but I was just experimenting with various things.
Regards,
Derek.

Re: TWebBrowser Container

Hi Derek,

Thanks for your reply. I'll try to use relative linking.
I'm truly grateful for your kind help........

Adam
God... please help me become the person my dog thinks I am.