Sharing private properties and methods

So I’m creating a custom control. It’s a canvas subclass. I also have a windows subclass (used as a popup) that is used only by the canvas subclass. I would like to share properties between the two classes without exposing them to class instances. How can I do this? The only way I know to do is create the window and it’s controls on the fly and use addhandler (from within the canvas subclass), but this seems to be a pain. Is there another way?

Put it all into a ContainerControl instead?

Or, put both classes into a module and make them Global, then add private interfaces to the module that exposes the private methods of each class (you’ll have to access the properties through methods). Each class can access the other through its interface.

You can’t add a window to a container control.

An interface would probably work but I’ve never used an interface. Right now I’m working at adding the window and the controls dynamically at run time using add handler. Although not easy this might be the best way to contain my custom control in one piece.

add them to a module
in the module make the window subclass private
make the canvas public
only things in the module can use the private items so only your canvas can use it
there are other things like the private interface etc but this should work for your purposes

Now I’m back to the same problem. I can’t add a window to a module unless it’s a subclass. This is fine but then I can’t add controls to the window subclass.

How are you using this Window subclass now? I’m trying to imagine what this control looks like and does.

I actually have several, but the one I’m working at now is a Flyout menu. I use a canvas for the base control. Then for the flyout I use a borderless child window so I don’t have to worry about the (unknown) controls it’s covering up. I could just use a bordeless child window for the control but then it doesn’t move with the window.

Here is a clip. The idea is like a toolbar with icons (no drawn on clip), that expands to a menu when hovering over it. It’s for an app that is intended to be show very narrow on the one side of the screen.

Well “window subclass” is literally

   add a new class to your project
   set super to Window

THIS you can add to a module

IF instead you did “new window” then try to add that to a module you cannot
That isn’t a Windows subclass - its a Window INSTANCE template

And functionally they are quite different

Interesting.

So when I create a window instance in the IDE then in code do:

Dim w1,w2 As myWindowInstance w1 = New myWindowInstance w2 = New myWindowInstance w1.show w2.show

I’m really creating 2 instances of an instance?

Ok enough of time wasted. I’ll leave it as is for now. Thanks to everyone for your help.

“instance” might not be the right name for the ones you CAN edit the layout in the IDE
Perhaps “template” is a better way to describe them
They’re not CLASSES - they look like they are in the UI but thats a convenient fiction
And at runtime they are NOT either - theres more to it than that
And that “more to it” is important - and also part of why you cannot put one into a module

When you say “new myWindowInstance” you are getting a new instance from that template - preconfigured with UI method properties event handlers etc
And there’s a pile of set up that makes that possible

And when you create a subclass by adding a class and then changing the super - its a different beast that doesn’t have all that setup associated with it
Its a slightly weird thing to get used to but its also not new

And if you leave “implicit instance on” there’s even a tad more baggage that goes along with all this :stuck_out_tongue:

Thanks for the explanation Norman. That makes perfect sense. I was just having trouble wrapping my head around it. The word template put it all together for me.

http://web.archive.org/web/20080321004712/http://ramblings.aaronballman.com/2007/06/windows_a_weird_odyssey.html

While this was written a decade ago its still “the truth”

And for anyone interested you can buy a copy of Aaron’s book Ramblings on REALbasic which is still full of useful stuff like this