On Dec 23, 2006, at 6:35 AM, Tom Benson wrote:

On 23/12/2006, at 9:47 AM, Tom Benson wrote:

Woudn't you need to cast it as a MyEditField (rather than a vanilla Editfield) in order to trigger a custom method..

ie.
if app.LayoutPraticiens.Control(i) isa MyEditField then
      MyEditField(app.LayoutPraticiens.Control(i)).raz

If the method is, as seems the case here, a method of MyEditField then yes and there will be a compiler error to tell you that raz is not a method of EditField.

The other two possibilities:
1) the method is in EditField and then a polymorphic override exists with a copy in MyEditField. In that case, despatching via the parent class will be legal and the normal virtual method resolution will take place. (In C++ terms, you are casting a pointer to point to the parent class.)

Are you sure Andy? I would have thought that

a) if you'd overridden an Editfield method, and
b) then cast a control in a loop like this as an Editfield and not as a MyEditfield

then the result would be a call to the Editfield function, and not the MyEditfield function...

He's right.

In fact I rely on this heavily in a number of my projects (being able to call a superclasses method that I have overridden by casting the object as it's superclass)


The correct way to do this is to call such a method using Super -- Super.Foo.

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to