Show a window by a text name

I want to open/show a window by dynamically constructed name. Is there any way to do this without opening the window first and scanning all open windows looking for it? I will have many windows and I think that would be slow and a resource hog.

The window name will have a fixed part and a variable part and or course will be text. If I try

Window("ConstructedWindowName").show

Xojo throws a compile error:

Type mismatch error.  Expected class Window, but got TextLiteral

I suppose I could examine the windows class and scan through it looking for a name match, but I haven’t figured out how to look at all my project’s defined windows, not just those that are open.

The only other solution I can think of is to build a Select Case statement with each possible constructed name and hard coding the associated window, but that would require constant maintenance when windows are added, deleted or named-changed. Ugh!

I look forward to hearing other suggestions.

That sounds like you are trying to show a Window TYPE
eg you design a window which you call frmMYWIndow

Then you try to show it in this way. That might work with implicit instantiation, but normally your windows are variables… instances of the type

dim mywin as frmMYWIndow
mywin = new frmMYWIndow
mywin.show

So if you have implicit instantiation on, and no instance of a window of that type, you probably need to do a select case

select case  constructedwindowname
case "Banana"
   Bananawindow.show  //shows the one and only default instance
end select

If windows of the type already exist and you want to bring them forward, you might iterate through the windows collection and look at some property to see if it is a window of the type you want.
If so, .show the item in the array

Jeff, thanks for the response.

[quote]So if you have implicit instantiation on, and no instance of a window of that type, you probably need to do a select case

select case constructedwindowname
case “Banana”
Bananawindow.show //shows the one and only default instance
end select[/quote]

Yup, that’s pretty much what I’m doing now, but I worry about it becoming a maintenance issue down the road.

What I’d really like to find is a collection of defined but not instantiated windows and then create an instance of the one I want. That would limit resource usage. My research hasn’t turned up anything yet.

Xojo’s introspection system does not provide a list of classes in the app. It lets you get info about a class or an object, but you have to specifically use the name of the class (GetTypeInfo) or an instance of it (Introspection.GetType).

So if you really want a method like:

ShowMyWindow("WindowName")

Then doing what Jeff suggests is your best bet.

What you want is pretty unusual, I think . What is your use case?

That sounds like a lousy window control.

You should have implicit instance turned off, then stire a reference to the window and the “dynamically constructed name” asociated with it, that way you will actually know what window to show.

Or

For i As Integer = 0 To WindowCount - 1 Dim w As Window = Window(i) If w <> Nil Then 'find if this window is the one that you want... End If Next