I use the snipped below:
Var f As FolderItem = FolderItem.TemporaryFile
HTMLViewer1.LoadPage(TextArea1.Value, f)

but I do no understand the use of f.

A bit of a background here.

My current project is a Desktop application that generates an html file (in a TextArea) and this is good.

I add a new window with an HTMLViever.

Now, that html calls (for display) some images. How can I display the images ?

Actually, the generated html is displayed; not the images (of course, I do not know how to thell to the HTMLViever Control were to read the images).

The images are stored in a folder.

Ideas ?

You want the HTMLViewer to display the image? Put something like this in your HTML code, then:

<img src="file:///path/to/the/image.jpg">

In your Xojo you would have:

Var f as FolderItem

f = new FolderItem ("/path/to/the/image.jpg", FolderItem.PathModes.Native)

My bad. I knew my explanation was short.

The feature have to be seen as a preview. The html file will be used with an internet browser. I do not want to make two versions: the one for debuggng in the application and another to be used with your default browser.

What I was thinking when I read the HTMLViewer.Load(String, f) syntax was: I have to pass the document folder in f.
But this is not he case, f have to be a file reference, not a folder.

My images are referenced as:
<img src="./images/my_image_001.png" alt=“image name”)

001 is a variable number that is inc as needed. If the document reference 32 entries, the images will be 001 thru 032… all stored beside the html file when saved.

The shared example is used here as is.

It needs to be a file at the location of the base path for relative references in the HTML to be resolved. That is, a relative reference is resolved from the location of the file referred to by the folderitem. I’ve always been confused by this, as well, but as long as you think of it as “relative to the file,” it makes more sense. I don’t think it even needs to be a real file, so you could take the folder where the images are, make up a child, and I think it would work. Or, just pass a folder item reference to one of the images. I’ve passed meaningless folders when there are no relative references, and it works fine.

Thank you Matthew, I will try tomorrow at wake up time (after coffee) !


you are correct.

Here’s my solution:

  Dim Data_FI As FolderItem
  // Ask the user for the associated data folder location
  Data_FI = SelectFolder()
  // Renders the document
  wRender.HTMLViewer1.LoadPage(TA.Text, Data_FI)

Note that I passed a reference to a folder (by error; awake time) instead of a file as the LR states.

Talking about the LR: it needs some additions, so the next reader will not hesitate to code.

The FolderItem parameter can be understand as a location to save the string before loading it in the HTMLViewer (what it is not).

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.