I must be missing something basic here…
I’ve subclassed a TCPSocket.
In an instance of my new subclass (called YTCPSocket), I don’t seem to be able to “Add” anything but Event handlers for the event definitions I created. All other items in the “Add To” context menu are greyed out on the instance.
I want to override existing methods on the subclass (or parent class) but just for this instance.
How does one go about doing that in Xojo?
Just add a method with same name, parameters and return type to override one.
And then use super.MethodName to call original in your code.
Thank you for your reply.
As I said earlier…
Methods in Subclass are public (in case that matters)
You need to make a real subclass, not just an item on a window.
So add a new class to project, set super to TCPSocker or whatever and then use that as super for the item on the window.
So you’re saying that when I drag/drop a subclass onto the window it does not create a “real” instance of that subclass? Why would that be?
Is your RemoteSocket as SUBCLASS or an INSTANCE?
I.E. did you create a class, and change its super to Socket?
or did you just drag a socket object into the project?
I just tried this (creating a class, changing super) and it works fine
I Created a subclass from TCPSocket. RemoteSocket is an instance of YTCPSocket. I dragged YTCPSocket onto the project. Creates an instance but I cannot override any methods. Does dragging not create an instance of the subclass? If not, then what is it doing?
If YTCPSocket is the custom subclass you created, then THAT is where you add things… You cannot add/alter an INSTANCE of a class which is looks like RemoteSocket is
That seems weird. I can alter the event handlers for each instance, but not the methods?
You attach event handlers in the window control to the class.
That’s the way it worked forever in Xojo.
But not Methods?
I must be missing something fundamental here.
Correct. You cannot add a method to an instance of a class, only to the class object itself. You can then choose the instance of the class to not call that method.
Again, seems weird, but such is life with Xojo. Thanks, all…
Seems I cannot call RaiseEvent to a super’s Event Definition in my subclass.
Have to do a dumb workaround of creating a method in my super that calls the event…
Events “go down” the class hierarchy - this pattern is called "chain of responsibility)
Methods can call UP the class hierarchy (using Super.XXXX)
And I also cannot override methods within an instance?
basically on an INSTANCE you get to set properties that affect the behaviour
and you get to implement event handlers (which ARE the behaviour mostly)
after that methods are for every instance of the class
exactly the same as a button, scrollbar, etc
Subclasses are the place to add methods, not the instance.
Gotcha. Guess I gotta re-do my classes a bit with this in mind…