On Apr 21, 2006, at 11:16 AM, Keith DeLong wrote:
I'd like a generalized function where I could pass any window class
and
close it if it is open. Something approximating this:
Function CloseWindow (W as Window)
For i as integer = (WindowCount-1) downto 0
if Window(i) isa W then Window(i).close
Next
End Function
The problem above is the compiler complains that w is not a class.
Is there a solution that I'm missing?
Perhaps; the problem is not entirely clear to me. Is it that you
want to close the framework-supplied instance of a window subclass,
if open?
Charles Yeomans
Yes. And the barrier to a simple general function like the one
above is that
one cannot pass a class as a parameter.
The easiest solution is to not use the framework-supplied
instance :) Unfortunately, it's easy to use, and so one does.
On the assumption that you're not going to create instances of, say,
PrefWindow other than the framework-supplied instance, you could do
the following -- add a shared method to PrefWindow.
Sub CloseWindow()
For i as Integer = 0 to WindowCount - 1
If Window(i) <> nil and Window(i) IsA PrefWindow then
Window(i).Close
Exit
End if
Next
End Sub
I'm not sure how much better this is, since such a method must be
added to each class (unless you want to engage in a bit of
subclassing), but at least the code is part of the class.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>