Recent

Author Topic: TIpHtmlPanel: How ro reload?  (Read 5123 times)

prof7bit

  • Full Member
  • ***
  • Posts: 161
TIpHtmlPanel: How ro reload?
« on: September 10, 2021, 11:36:35 am »
I have a TIpHtmlPanel and a TIpFileDataProvider.

If I call OpenURL('help/somefile.html') on the IpHtmlPanel it will correctly open and display the file "somefile.html" in the folder "help" (relative to current directory)

if I call the same method again with the exact same argument (because I could not find a reload method) it will throw an exception:

"Resource unavailable:help/help/help/somefile.html"

The same if I try to open any other file.

* why did it prepend the same folder twice?
* How would I properly cause a reload (because file contents changed)?
* How can I can I reset it back into a state where I can call the OpenURL() method a second time?

 

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TIpHtmlPanel: How ro reload?
« Reply #1 on: September 10, 2021, 02:03:44 pm »
What are you doing exactly? Please post a small project which basically follows the steps in your application and demonstrates the issue.

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: TIpHtmlPanel: How ro reload?
« Reply #2 on: September 10, 2021, 04:19:09 pm »
I want to show some help text that is only a little more complicated that plain text, essentially it just needs headings, tables and plain text. So I thought TIpHtmlPanel should be plenty enough for this. I am then feeding it with handcrafted HTML that carefully avoids any fancy stuff that it cannot display.

For testing the rendering of my HTML during development I wanted the ability to easily reload the file while I am writing the HTML in a text editor: Edit the html, save it, hit reload on my help form to see if it looks correct.

relative to the application there is a folder "help" and inside is "somefile.html"

Initially I load it with

Code: Pascal  [Select][+][-]
  1.   FPanel.OpenURL(FileName)  // FileName is 'help/somefile.html'
  2.  

This works fine. The first time.

Executing the exact same line of code a second time gives the above mentioned error. It will try to interpret the URL as relative to the loaded document but even this won't really work, I have the impression the OpenURL() method is broken anyways. For example it errors out on 'file://' only a few lines above that section of code where it would test the string for 'file://', very strange...

Anyhow, meanwhile I have found through experimentation that calling

Code: Pascal  [Select][+][-]
  1.   FPanel.SetHtmlFromStr('');
  2.  

before I use OpenURL will reset it into the state where OpenURL will work again.

I got it working now for what I need it, but I already found a rendering bug: It will ignore TextColor for Text inside Tables and render them black, this makes it harder for me to switch theme colors from light to dark, I need to provide two different stylesheets, I was hoping I could avoid this by just changing thet default colors as it seems to be intended to work that way because it partially works already, I will file a bug in the next few days.
« Last Edit: September 10, 2021, 04:22:39 pm by prof7bit »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TIpHtmlPanel: How ro reload?
« Reply #3 on: September 10, 2021, 05:29:12 pm »
Since the IpHtmlPanel is poorly documented I am attaching a simple HTML editor demo to get you started. You can edit the html text in a SynEdit with HTML highlighting, and with the Preview button you can have a look at the output in the HTML panel. I also added a handler for displaying images.

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: TIpHtmlPanel: How ro reload?
« Reply #4 on: September 10, 2021, 06:20:09 pm »
Since the IpHtmlPanel is poorly documented I am attaching a simple HTML editor demo to get you started. You can edit the html text in a SynEdit with HTML highlighting, and with the Preview button you can have a look at the output in the HTML panel. I also added a handler for displaying images.

Thank you for the example. I think I have seen something similar already, but not yet tried it.

What I find interesting is that you need a handler for OnGetImage() because when you use OpenURL() instead of one of the SetHTML*() methods then it will load the images (and also external stylesheets) just fine without having anything extra to do!

Probably because then it knows the path to the file and everything relative to it. And I am using an TIpFileDataProvider and not an TIpHTMLDataProvider. Maybe this is the reason I don't even have a Property "OnGetImage" and it just works out of the box.

If I set the html text directly it won't find the images, at least not when I'm not in the same folder as the files.

« Last Edit: September 10, 2021, 06:42:39 pm by prof7bit »

Roland57

  • Sr. Member
  • ****
  • Posts: 423
    • msegui.net
Re: TIpHtmlPanel: How ro reload?
« Reply #5 on: May 12, 2023, 06:18:32 am »
Since the IpHtmlPanel is poorly documented I am attaching a simple HTML editor demo to get you started. You can edit the html text in a SynEdit with HTML highlighting, and with the Preview button you can have a look at the output in the HTML panel. I also added a handler for displaying images.

Very useful example (as usual).

The example from the wiki doesn't work when the HTML document contains pictures (tested with Lazarus 2.2.6). It throws a weird blank window, with an error-like sound, and no text. Maybe we could add a note in the wiki page, with a link to this example.
My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018