About Me / Self

XOJO 2021r11 and Windows 11

I have a class for a puSilent = a PopupMenu that does not act when the change is done in code, but only by selecting in the popupMenu itself.
In the code they use : PopUpMenu(Me).SelectedRowIndex
What is the difference between
PopUpMenu(Me).SelectedRowIndex and Me.SelectedRowIndex
or the same for ‘self’
PopUpMenu(Self).SelectedRowIndex and Self.SelectedRowIndex
Me referes to the puSilent PopupMenu.

Hi, there is a dedicated Me vs. Self entry in the documentation that explains it in detail:


Edit: Without seeing the project, PopUpMenu(Me).SelectedRowIndex sounds redundant to me, it will probably work fine using Me.SelectedRowIndex.

Thanks for the reply.
But sorry my question is not about the difference between Me or Self.
That difference I understand.
My question is about the difference between
PopUpMenu(Me).SelectedRowIndex and Me.SelectedRowIndex


Ok. I saw your last edit on your answer.
Both solutions are ok in XOJO.
There is no difference ?


That strikes me as simply casting the Me as a PopUpMenu, which it already is. You should only need to cast when you are not offered the desired subclass methods. Since your puSilent already refers to a PopUpMenu, adding the cast is not harmful but it does seem redundant and not necessary.


Thanks for the reply.
Indeed both codes work fine, but I needed to be sure that there was not some difference.


1 Like

Perhaps you would find this video on You Tube helpful. @Geoff_Perlman posted it a few weeks ago, and goes over some concepts of Object Oriented Programming.

Within it, one thing that may help clear up what you seem to be doing here is where he defines a class and a couple of subclasses with the other class as their “super”. He then defines an array of objects of the top level class, and adds elements including some that are actually subclassed objects. When dealing with elements that are a subclass, he then shows how casting as a subclass allows access to the subclass specific properties or methods not available in the parent class.

In your case, you appear to just be casting Me as the type of object it already is, so you already have access to the SelectedRowIndex property. Making the cast what the IDE and compiler would treat is as anyway. Thus no difference in the code other than readability. And readability is a subjective topic.

1 Like

If your PopupMenu subclass overrides the SelectedRowIndex property then Me.SelectedRowIndex will reference your subclass property and PopUpMenu(Me).SelectedRowIndex will reference the superclass (original) property.

This is a combined picture of the puSilent class.
The changes I made in green are working.
The change i made in Red gave me a error → StackOverflowException
So somehow there must be a difference.

I explained this in my previous post.

You have overridden the SelectedRowIndex computed property. This means that accessing SelectedRowIndex will call your version and not the version built into the class that Xojo provides.

Calling Self.SelectedRowIndex = value in your SelectedRowIndex computed property setter is just calling your method over and over which causes a StackOverflowException.

Calling PopUpMenu(Self).SelectedRowIndex = value calls the superclass (Xojo) version which changes the property value.

Sorry, I had missed the fact puSilent is itself a subclass of PopUpMenu and thought puSilent was just a control of type PopUpMenu. So what @kevin_g says does in fact explain the difference, and the cast is not simply redundant as I presumed. It actually changes whether you are referring to the subclass computed property or the super property.

Thanks everybody for the replies.
I now understand the code.