Share methods and properties between window instances

Hi,

I’m creating my own Drawer window for Cocoa. My basic window (containing no controls) contains several methods and properties to show and hide the window that I’d like to share between instances of the window. As it seems I can’t sub-class a window, is there any other way I can have these methods and properties appear in or be accessible to windows that I’d like to be a Drawer v2?

Thanks in advance,

Mark

You cannot subclass a window, but you CAN subclass the Window class. Create a new class in your project and make its Super “Window”. Put your methods and properties in the new class. Then create a new window and set its Super to your class. Voila! It now has all your methods and properties.

Great. Thanks a lot. Works a treat.

Mark

I used the technique above, but now I cannot get the active window. In the past I used the code

Dim w as Window

w=Window(0)

Then I could pass w as a window object to any method.

I created a class called WindowBD with its Super as Window

Using the code

Dim w as WindowBD

w=WindowBD(0)

Returns an error "expected class WindowBD but got int32

Any suggestions?

[quote=211263:@Bryan Dodson]I used the technique above, but now I cannot get the active window. In the past I used the code

Dim w as Window

w=Window(0)

Then I could pass w as a window object to any method.

I created a class called WindowBD with its Super as Window

Using the code

Dim w as WindowBD

w=WindowBD(0)

Returns an error "expected class WindowBD but got int32

Any suggestions?[/quote]

Why do you add “(0)” to WindowBD ?

Go w = WindowBD and you should be fine.

Be aware that as it stands, if WindowBD has implicit instance on, it will display a new WindowBD.

[quote=211263:@Bryan Dodson]Dim w as WindowBD

w=WindowBD(0)[/quote]
This looks like you’re trying to use WindowBD() like the Window() function. It doesn’t work like that. There is only one Window() function and it returns only the Window type. If that Window happens to be a WindowBD then you can cast it.

[code]dim w As WindowBD

dim temp As Window = Window(0) //get frontmost window
if temp <> nil and temp IsA WindowBD then //if there is a window and it’s a WindowBD
w = WindowBD(temp) //cast it
end

if w <> nil then
//work with w
else
//no windows or the front one isn’t a WindowBD
end[/code]

Fantastic! Casting worked. Thank you very much!