User manual example doesnt work

In Book 4 - Development User Manual on page 55 it says “Don’t Use Implicit Page Names” which I have been using so I changed all my code to use what it suggests:

Dim page As WebPage1 page.Show

The problem is that the above is now giving me a Nil Object error and I am not sure why. I only ever want one instance of the page for a session within the project. Also I notice that their is an option under Behavior for a web page called “Implicit Instance” but cannot find any details about what this does.

Dim page as NEW WebPage1

You need an instance. The code should be:

Dim page As New WebPage1 page.Show

I’ll get it updated.

If Implicit Instance is True (On), then WebPage1.Show works. If it is False (Off), then you have to do code like above.

This has come up several times, and I wanted to know what difference does it really make?

I did some simple tests and could find no appreciable difference in performance between the two methods. To make sure I was testing the supposed advantage of non-implicit pages, I change the text of 8 labels on the target page before showing it, so that I was making a total of 9 calls to the page name (8 labels and then the .Show call). There was no real difference in time taken to show each page - implicit or not (I used microseconds to measure the performance).

So, why would it be worth the trouble and time to setup non-implicit pages?

To protect yourself from making stupid coding mistakes. Like

if Window1.Visible then
   // oops! window1 wasn't instantiated or visible yet, but we just created it and made it visible.

You can get strange and unpredictable results from implicit instantiation.

Another significant difference is that you can access the properties of a non-implicit window after closing it, but you can’t do that with an implicit window.

w.ShowModal
x = w.Results
// Yay! we got good values
Window2.ShowModal
x = Window2.Results
// Boo!  All we got were the default values from a freshly instantiated Window2

Good points, but still not really selling me on the benefit. I am consciously aware of the auto-instantiating and code likewise. And I don’t use post-close properties (isn’t that what the Dismissed event is for?).

But the crux of the matter is that the only “reason” that the documentation gives for this is performance of the framework. And from what I have observed, this is simply not true.

Not really the same. You can use Dismissed and push values out of the window, or use post-close and pull them. Opposite sides of the fence.

There should be a slight performance benefit, since implicit windows incurs some function call overhead, but as you have seen, it is minimal. FWIW, I use implicit instantiation frequently. I also use non-implicit instantiation where I feel it makes sense. There is nothing inherently wrong with implicit instantiation. It’s not like DoEvents or anything.

Which is not the message you get from the documentation (and other comments from Xojo about it). As it stands, the docs make it sound like implicit is bad and should be avoided.

Just curious, but where in the documentation does it warn against implicit instance? I’m not seeing that.

[quote=80839:@Jay Madren]This has come up several times, and I wanted to know what difference does it really make?

I did some simple tests and could find no appreciable difference in performance between the two methods.
[/quote]
Its not a performance issue at all
But you can get unexpected behavior when you do something like Tim mentioned

It’s what started this thread. Book 4, Optimizing Web Apps, page 58. Ok, maybe it doesn’t say implicit is bad, but just that you can optimize performance if you don’t use it. But again, my tests show that’s not really true.

Sounds like that information may be out of date. At one time, I have no doubt it was true, but they have optimized things quite a bit with sessions and such (the implicit instance is session specific). It may be worth having @Paul Lefebvre consult the engineers and see if it needs to be revised.