[Gambas-user] Inheritance issue... or visibility issue... or something I think
Benoît Minisini
gambas at ...1...
Sat Jun 11 13:22:23 CEST 2016
Le 11/06/2016 11:54, Jorge Carrión a écrit :
> I think that I miss something here.
>
> I have a control A inherits usercontainer. It has a property, let's say a
> connection called Conexion
>
> I have another control B inherits, let's say a listbox. It has a Private
> $conexion as connection variable.
>
> in Sub _new() or B, I code this
>
> $conexion = me.Parent.Conexion
>
> and get a "wanted variant get function" error.
> If I stop de execution on that line an double-click on me.parent an I can
> see the Conexion property without problems.
>
> But If I code instead:
>
> Dim o as object
> o=me.parent
> $conexion=o.Conexion
>
> Then it works. I have doing something wrong... but, what?
> See the attached project if I did not been clear enough.
>
> Best Regards.
>
Me.Parent is a Container, so it does not know the 'Conexion' property.
To be able to access the 'Conexion' property, you must assign Me.Parent
to either:
1) A variable whose datatype knows the Conexion property: A, or any
class that inherits A.
2) An Object variable.
3) A Variant variable.
If you use 2) and 3), then the property access is resolved at each call,
which is slow.
If you use 1), the property access is resolved once (the first time it
is used), and each successive access is fast.
Maybe it should be explained in the "Gambas object model" wiki page.
Regards,
--
Benoît Minisini
More information about the User
mailing list