Hello all. I am experimenting with objects.
Does anyone know if it is possible to override or extend methods and events in Xojo?
Hello all. I am experimenting with objects.
Does anyone know if it is possible to override or extend methods and events in Xojo?
Jose the short answer is yes. You can have a look at this project to see how I use overloading.
I see.
LabelToShow.Text = LabelCaption
// Calling the overridden superclass method.
Super.Showmodal()
Return TextToReturn
You use “Super” to call showmodal.
Look at the following case:
I can see the opening event and put code in it since I have not used such an event in my class.
Now imagine if I use it.
Xojo will no longer present this event automatically. But I need it and code inside with overriding.
How can I add the event?
In My_Class add an event definition called Opening, at the end of your Opening Event Handler add RaiseEvent Opening. This will “bubble” the opening event up to the next level i.e. when you use the control on your web page.
If you right-click your Opening event, you will be offered the ability to create an identical event definition. Then all you need to do is call
RaiseEvent Opening
In your code where it is appropriate.
BTW, kudos to whoever came up with that one. Wish I thought of it myself.
As you probably remember, it’s almost a necessity when building a framework because you do that over and over.
Phases to solve the question:
Create class.
Open an event in that class. I select the Opening event in my sample.
Add an Event Definition in the same step 1 class. Name the “Event Name” property. Continue with the sample write Opening.
Write the code for the Opening event plus the “RaiseEvent Opening” code.
When you put the class in the form, you can open the Opening Event and add more code.
Thank you very much for your comment, Greg. I also thank Wayne and Thom for their responses.
I put the steps to achieve what I wanted.
If you have comments, I can modify them to improve the explanation of the steps so that others can solve the same issue.
My comment was that instead of step 3 you could just right-click the event and create the event. it makes a duplicate of the original event definition for you. While it’s not necessary for something like “Opening” it could be if the event has multiple parameters and a return type.