WindowX.show doesn't open the window

I want to open a window and afterwards to fill some controlls with new values

windowX.show
windowX.textfield1.text = "Wonderland"

But always get NilObjectexcample-error

Assuming you created a windowX in the IDE

Dim w as new windowX
w.show

P.S. You really should work through the tutorial and learn the difference between class and instance. Your question clearly tells me that you didn’t.

Robert on which line do you get the NilObjectException? Your code should work if you haven’t changed the Implicit Instance setting on WindowX. If you have then Markus’ option will work and you can use w.TextField1.Text = “Wonderland”.

Let us know how you get on.

As a matter of fact - I really don’t know how to change the Implicit Instance setting on a Window
But I solved the problem by

dim ww as window ww = new ERBuchung

That is NOT the correct answer.

Dim ww as window makes no sense.

What window? “window” is the generic class name of ALL windows in your app.

You add different windows to your app, like a main window, a preference window, an about window.

You give them names like window1 or MainWindow or PreferenceWindowso you can refer to them.

You set them up as you would like them to look by adding buttons, textfields, listboxes etc.

Now if in your app you need a new window (= instance) of type MainWindow (= class) then you do

Dim myMainWindow as new MainWindow
myMainWindow.show

Something like dim w as new window should be flagged as an error IMO.

Your “solution” only works because ImplicitInstance is on, so ww = new ERBuchung will create a new instance of ERBuchung even without the dim statement.

That is a completely wrong comment. Of course there are situations where you want to use Dim ww As Window and then assign a specific subclass instance to ww.

Do you really think that is one of them???

It depends of the task – we don’t know.

I assume you meant: dim w as window because dim w as new window will not compile. Anyway, this your sentence is really as wrong as wrong can be.

[quote=182790:@Markus Winter]Your “solution” only works because ImplicitInstance is on, so ww = new ERBuchung will create a new instance of ERBuchung even without the dim statement.[/quote]… was your comment to Robert’s solution:

dim ww as window ww = new ERBuchung
This has nothing at all to do with ImplicitInstance being turned on. It is valid Xojo code and will run whether ImplicitInstance is on or off.

I stand corrected then.

Thanks to both of you.

I do not really care, if it is “correct” coding. It runs now. That is most important to me.

I do have troubles with chronology of commands. I do not expect, that a window, which is opened with a Window.show command doesn’t have any control in it. Maybe it has something to do with implicit instance, but I never changed there anything.
So after these two lines it worked again, what is the only important thing for me.

[quote=182950:@Robert Blazek]Thanks to both of you.

I do not really care, if it is “correct” coding. It runs now. That is most important to me.

I do have troubles with chronology of commands. I do not expect, that a window, which is opened with a Window.show command doesn’t have any control in it. Maybe it has something to do with implicit instance, but I never changed there anything.
So after these two lines it worked again, what is the only important thing for me.[/quote]

If you want a window to have controls on it, do not use dim WW as Window which creates a blank window.

Design a window in the IDE with all the controls you need, and to display it, simply use :

myWindow.Show

That is enough to display it with all the controls inside. Unless you specifically set it otherwise, windows implicitly instantiate.

This statement does not create a window. It allocates storage space for a pointer to a Window.

Mchel - I always do so. And it always worked, just to state window1.show.
But in this case when I debugged, because it diddn’t work, ther was no content in the window.
Sometimes I am handing values to a new opened window, because they are local to another window.
And I got always an NilobjectExcaption. Because there was no textfield in the window.

So after my two lines there was everything there.

To tell me, what I did was wrong is very funny, because now it works, as I did wrong :slight_smile:

And I did not set implicitly instantiate off. It is on in all my windows.