Using Introspection I may know (for exemple) if a window is open
Dim intro as Introspection.TypeInfo = Introspection.GetType(app.window(i))
if intro.Name = name then
but how may I get acces to the instance?, to , for example, close it
Using Introspection I may know (for exemple) if a window is open
Dim intro as Introspection.TypeInfo = Introspection.GetType(app.window(i))
if intro.Name = name then
but how may I get acces to the instance?, to , for example, close it
Errt you don’t need Introspection to determine if a window is open. I was told the Window() array can change order as you access the items, so I always copy it to a local array first.
dim aroWindows() as Window
for i as Integer = (WindowCount - 1) downto 0
aroWindows.Append(aroWindows(i))
next i
for i as Integer = 0 to aroWindows.ubound
dim oThis as Window = aroWindows(i)
if oThis isa winWindowClass then
// This is the window we're looking for
oThis.Close
end
next i
Well, in fact, if the window is open I want to close it, but if it’s not, then open it.
I just receive the window’s name
Easy enough, slight tweak
dim aroWindows() as Window
for i as Integer = (WindowCount - 1) downto 0
aroWindows.Append(aroWindows(i))
next i
dim oTargetWindow as Window
for i as Integer = 0 to aroWindows.ubound
dim oThis as Window = aroWindows(i)
if oThis isa winWindowClass then
// This is the window we're looking for
oTargetWindow = oThis
exit for i
end
next i
if oTargetWindow = nil then
// Window isn't open, let's open one
oTargetWindow = new winWindowClass
oTargetWindow.Show
else
// Window is open, close it
oTargetWindow.Close
end
(both chunks written in the forum post editor, that’s how often I need this boilerplate code)
Thanks Tim, but it’s not exactly I’m looking for.
Just receiving the window’name I would like to know the type (about ten), i.e avoiding the
if oThis isa winWindowClass1 then
elseif oThis isa winWindowClass2 then
elseif oThis isa winWindowClass3 then
In fact this is how now is right now my code, with a select case.
Imagine we have a Specialwindow
we open it as
Var w as new SpecialWindow
w.show
But about if you just receive the name as string “SpecialWindow”
Var w as new name
doesnt work
[quote=467975:@Enric Herrera]Well, in fact, if the window is open I want to close it, but if it’s not, then open it.
I just receive the window’s name[/quote]
the name is not unique though
it is IF you only ever open one instance
as soon as you have a second its name is the same and now you have problems
Thw window’s name (subclass name) no the title.
And yes there is only one instance of each class, because if received it as open, then I close it.
Probably I’m not asking correctly the question.
Var w as new myWindowType
w.show
If I receive a string with the subclass name: “myWindowType” how may I
Var w as new ?????
w.show
I don’t recommend using this but you can construct a class like this way:
http://documentation.xojo.com/api/language/const.htmlructorInfo
Bottom of the page. You may want to check if the name is the class name then call invoke it’s constructor
Ok, thaks to all, I see it was not a good idea, I’ll continue with the select case.