Can an event handler call a method on anotther object ?

Hi,

sorry, I couldn’t come with a different title. Please stay with me.

I have a Web app where on a page there is a list to the left and a WebHTMLViewer to the right.

The list

I can’t use a WebList because I need to mix texts an images on a ‘line’. So I use a custom list. That list is a WebContainer and each 'line’in the list is another WebContainer displaying data to the user. A query to a database returns a certain number of records, and for each record I got I add a ‘line’ (WebContainer) in the list, one below each other.

The WebHTMLViewer

This will display a PDF file when the user click on one of the ‘lines’ (WebContainer) in the left list. I need then to display the proper PDf file.

In order to achieve my goal, I added code to the MouseUp event on a ‘line’, and added a method and properties to the WebPage. The logic works this way:

MouseUp event

Gets a a property for the ‘line’ clicked, and call a method on the WebPage (LoadPDF) with a parameter, the property of the ‘line’

LoadPDf method

  • Using the argument, a query is done in a database that returns the PDF file
  • The PDF file is set on a WebFile, a property of the WebPage
  • and the WebHTMLViewer URL is set to the WebFileURL

Question: is there something wrong with the way I coded this ?

I asked because I have one issue. Everything else works in the LoadPDF method, getting the PDF file etc, but the PDF does not display in the WebHTMViewer. Since it’s hard to debug, I added one more line of code to the method, which is ShowURL() set to display the same PDF file from the same WebFile in a new tab. And in the new tab, I get the PDF.

I get no error setting the URL in the WebHTMLViewer, it simply does not display the PDF as if it’s URL was not set, and the debugger shows that it’s set.

What is wrong exactly ? As a test, a button was added to the WebPage, calling the LoadPDF method with a hard coded parameter, and then the WebHTMLViewer correctly displays the PDF file.

Is there an error in my code ? If not then what’s wrong ?

Thanks a million

The guy I am developing for font out a way to solve the issue, trying things. So here is the explanation.

The MouseUp event saves a ‘line’ item in a property of the WebPage and calls the LoadPDF method.

LoadPDF gets the property needed for the query from the saved ‘line’ item ’ . . . well I should say “tries” to get the property but runs into an issue because for her, the saved ‘line’ item is Nil. How come can’t the method access the just saved ‘line’ item ? I don’t have the answer, but adding WebPage.Show before calling LoadPDF solves the issue.

I don’t know if this is valid in your case but you can sometimes run into trouble when you try to invoke a method that causes an event from inside another event handler.
The best way to avoid these troubles is to make sure the system has time to update the GUI and return to the main event loop. Probably the most elegant way is to use a Xojo.Core.Timer.Calllater 0, (weak)AddressOf LoadPDFMethod, URLString in the first event handler.

Ulrich,

this is exactly the advise I was looking for ! I am pretty sure that calling that method from an event handler is my issue and was looking for a way to call indirectly the method. I will give it a try and post back.

Do you know a good book on Xojo ? I am looking specifically for Web Development, because that seems to be another animal !

Thanks again

Ulrich,

can’t tell if your suggestion works :-(. I need to keep the Webpage1.Show else where. Since I need to complete the prototype, I will have to put aside that issue unfortunately. But I will get back to it for sure.

Whatever works for you, Gilles!
About books: Sadly no. Many recommend The Definitive Guide to RealBasic by Matt Neuburg, but I have never read it and the TOC does not include the web framework.
Eugene wrote an eBook about web programming with Xojo available on http://www.xdevlibrary.com. It was written in 2014, but the web framework has only gained a few features over the last years.

@Ulrich Bogun

Hi Ulrich,

still struggling with my issue. Seems like things do not happen when they are expected. I am wondering if there is some way to trace program execution. I would juts need a list of entered events and methods, maybe seeing the order would help me getting what’s wrong. I found that , but System.DebugLog doesn’t work at all - I wonder if it ever did :-(. Do you have some way to achieve what I am looking for ?

Thanks

You should post in the Web channel. That would make things easier for other forum members.

I suppose you are under Windows.

Get DebugView from Microsoft ; it will show system.debuglog messages under Windows for Web programs.

https://docs.microsoft.com/en-us/sysinternals/downloads/debugview

Hi Michel,

I already installed debugview, I am running Windows 10. I either get nothing in there, too much entries or it goes bananas. System.DebugLog calls don’t produce anything in debug view :-(.

The Web channel, I should have checked that. Is there some way I can move this post from General to Web ?

Just moved it to Targets > Web. Thanks