Creating windows at run-time

The following piece of code doesn’t display the close and Min,Max buttons and it is not possible to resize the window. What is wrong?

w =  new DesktopWindow
w.Type = DesktopWindow.Types.Document
w.Title = "TestWindow"
w.Resizeable = True
w.HasCloseButton = True
w.HasMaximizeButton = True
w.HasMinimizeButton = True
w.Height = 400
w.Width = 600
w.Top = 200
w.Left = 600
w.Visible = True
w.Show

Have you looked at the doc to see whether any of these are allowed to be set in code, or are only settable in the IDE?

I didn’t… It seems these properties are read-only. They cannot be set in code. But how can we create a window at run-time with the above properties (Close, Min, Max, Resizable)?

why can’t you just define new window in IDE as a template, with all properties set as you like, and then show it from code?

w = new MyWindowAsDefined
w.show

?

1 Like

Yes, of course I can do that. But, the problem was unexpected for me: during coding also the read-only properties are suggested. This was the reason why I was so astonished why this small piece of code didn’t work… Tim, Pawel thank you for your help.

Actually that’s interesting. They should show up if you do:

myvar = w.Resizeable

because you’re allowed to read them. But I’m a bit surprised they show up if you try to write them as with:

w.Resizeable = True

Anyone know if that’s actually a bug?

What is a bug? It is difficult to define for this kind of problems. I would prefer to get a warning when I try to use this erroneous statement.

1 Like

It should generate a compiler warning and if memory serves in the old API it did. I would open an Issues ticket for it.

1 Like

I’m talking about a command-completion issue.

We must avoid using a read-only property incorrectly. Now everything seems OK since there is no error message or warning. I didn’t expect these properties to be defined as read-only. So I didn’t check the docs… I have no idea why these properties are defined as read-only.

When I have unexpected result(s), I start reading the documentation; usually, it is my fault, 'cause I forgot something (or I misread the docs).

In fact, since many years, I cannot do anything without reading the documentation… :frowning:

Emile, I have learned my lesson: from now on I will first consult the documentation again before posting a new issue on the forum…But this problem seemed so simple…

I don’t think it’s always a mistake to ask in the forum if you’ve already tested things and they don’t behave logically.
In this case, the IDE should have thrown a compiler error. The fact it didn’t would have meant the documentation probably would tell you the same (I mean, the issue is in the IDE; that’s the thing to fix).

1 Like

I found this interesting (and distressing) enough to create an issue:

https://tracker.xojo.com/xojoinc/xojo/-/issues/75907