Override or extension of methods and events

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.

1 Like

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:
Captura de Pantalla 2023-05-15 a la(s) 19.00.25

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.

1 Like

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.

1 Like

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:

  1. Create class.

  2. Open an event in that class. I select the Opening event in my sample.
    Captura de Pantalla 2023-05-16 a la(s) 15.18.28

  3. Add an Event Definition in the same step 1 class. Name the “Event Name” property. Continue with the sample write Opening.

Captura de Pantalla 2023-05-16 a la(s) 15.19.39

  1. Write the code for the Opening event plus the “RaiseEvent Opening” code.
    Captura de Pantalla 2023-05-16 a la(s) 15.25.46

  2. When you put the class in the form, you can open the Opening Event and add more code.
    Captura de Pantalla 2023-05-16 a la(s) 15.27.57

Captura de Pantalla 2023-05-16 a la(s) 15.28.33

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.

1 Like