TIpHtmlPanel: How ro reload?
lazarus / 5-Lazarus Extra Components
----------------------------------------------------------------------
prof7bit · 2021-09-10 09:36
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 · 2021-09-10 12:03
What are you doing exactly? Please post a small project which
basically follows the steps in your application and demonstrates the
issue.
----------------------------------------------------------------------
prof7bit · 2021-09-10 14:19
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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
FPanel.OpenURL(FileName) // FileName is 'help/somefile.html'
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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
FPanel.SetHtmlFromStr('');
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.
----------------------------------------------------------------------
wp · 2021-09-10 15:29
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 · 2021-09-10 16:20
Quote from: wp on September 10, 2021, 05:29:12 pmSince 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.
----------------------------------------------------------------------
Roland57 · 2023-05-12 04:18
Quote from: wp on September 10, 2021, 05:29:12 pmSince 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.