Use HTML viewer to load an image.

You must have another issue. I just checked HTMLViewer does load perfectly well an image with this in the open event :

dim f as folderitem = SpecialFolder.Desktop.child("studebaker.jpg") me.LoadURL("file://"+f.shellPath)

Note I am using the same syntax as your code, and even went as far as using shellpath. The picture loads just fine.

You mention loading that into another window. If you forgot to create an instance and implicit instance for the window is not on, that would do a very nice NilObjectException. Why don’t you put a break on top of your code, and go step by step ? Chance are the bug is not in the LoadURL at all.

Going back to the code posted in the original question, if f is a picture, you might be better served by an ImageWell instead of an HTMLViewer?

The OP wanted to display an animated Gif. Imagewell would not be capable to show the animation.

[quote=181317:@Michel Bujardet]You must have another issue. I just checked HTMLViewer does load perfectly well an image with this in the open event :

dim f as folderitem = SpecialFolder.Desktop.child("studebaker.jpg") me.LoadURL("file://"+f.shellPath)

Note I am using the same syntax as your code, and even went as far as using shellpath. The picture loads just fine.

You mention loading that into another window. If you forgot to create an instance and implicit instance for the window is not on, that would do a very nice NilObjectException. Why don’t you put a break on top of your code, and go step by step ? Chance are the bug is not in the LoadURL at all.[/quote]
I did not just mention it. I gave an example where I instantiated the window (explicit instance off). I also put the break inside the window, right before the HTMLViewer.LoadURL method and no exception is raised. So the problem really is with the LoadURL method. In your example you use SpecialFolder.Desktop and f.ShellPath, both of which I did not, so it’s not a fair comparison. But it does demonstrate that “file://” also works instead of “file:///” as f.URLPath uses on Windows, which explains why the executable works just fine.

I could not reproduce your error, though. The only way I can think of is if you try to loadURL on a control within a window that has not been properly instantiated. Then of course, since the window does not exist yet,it would trigger a nilObjectException.

Would you care to post your project ?

[quote=181344:@Michel Bujardet]I could not reproduce your error, though. The only way I can think of is if you try to loadURL on a control within a window that has not been properly instantiated. Then of course, since the window does not exist yet,it would trigger a nilObjectException.

Would you care to post your project ?[/quote]
OK, now I understand why you can not reproduce it. I just checked on newer RS versions and it appears this bug was fixed in RS2012r2.1 (for maintaining older software I still used RS2011r4.1). I also checked the release notes and it appears that several compiler issues were fixed. This code now just runs fine from the IDE:

[code]dim url as string

url = “file://” + path + file
hvAgreement.LoadURL(url)[/code]

The NiilObjectException the OP had must have been another problem. So I’m glad we clarified this one. And no, I would not have posted the entire project. It is a billing system with which I partially earn a living. But thanks again for clarifying Michel.

I stand corrected, the NilObjectException also occurs with RS2012r2.1

I do not know about the current XOJO version though.

[quote=182283:@Frank Hoogerbeets]I stand corrected, the NilObjectException also occurs with RS2012r2.1

I do not know about the current XOJO version though.[/quote]
Have you tried Michel’s suggestion of using URLPath the way you’re supposed to? What are the results from that?
Any time you can use Xojo built in locations and functions you should, you will get better results.

dim gifItem as FolderItem = TPSF.Resources.child("anim.gif") HTMLViewerInstance.LoadURL(gifItem.URLPath)

[quote=182324:@Tim Parnell]Have you tried Michel’s suggestion of using URLPath the way you’re supposed to? What are the results from that?
Any time you can use Xojo built in locations and functions you should, you will get better results.

dim gifItem as FolderItem = TPSF.Resources.child("anim.gif") HTMLViewerInstance.LoadURL(gifItem.URLPath) [/quote]
Yes I have. It makes no difference. It is in the LoadURL method itself, and as I said, only on Windows when run from the IDE. But I can live wih it as I only use RS to keep some older projects alive.

XOJO will not be an option as long as Linux support is low. In the meantime I have found my way to Object Pascal with Lazarus. It will just take a while before all my RS projects are ported.

[quote=181349:@Frank Hoogerbeets]dim f as folderitem = SpecialFolder.Desktop.child(“studebaker.jpg”)
me.LoadURL(“file://”+f.shellPath)
[/quote]

When I place the code I posted in the Open event of an HTMLViewer in 2011R4.3, no error and the picture displays.

But when I use the same code for a gif file, it simply does not display, as if the file was not there. NO error, though

dim f as folderitem = SpecialFolder.Pictures.child("fontmenu.gif") me.LoadURL("file://"+f.shellPath)

Problem seems to be the HTMLViewer itself, specifically with gif files. If I drop all kinds of picture files over the HTMLViewer, they all display fine, but gif files.

But visiting fontmenu.com where fontmenu.gif is on the upper left corner, it displays. So the workaround is to encapsulate the gif inside a small HTML page, such as :

[code]

[/code]

That displays very well my animated gif in 2011R4.3.

Here is how to use LoadPage to be able to select any file, which you can easily make into a method :

dim f as folderitem = SpecialFolder.Pictures.child("proud-old-glory.gif") dim mypage as string = "<html><body><img src='"+f.urlpath+"'></body></html>" Dim f2 As FolderItem = GetTemporaryFolderItem me.loadpage(mypage, f2)

All tested.