[Gambas-user] Extending classes in existing components
Tobias Boege
taboege at ...626...
Sat Nov 1 13:01:55 CET 2014
Hi,
periodically we find ourselves in the position that we want to add some
specific functionality to classes in existing components, mainly in gb.form.
More often than not this is a trivial thing like being able to add an
Observer for one child in a compound control or change a font or some other
little thing that is there but not exposed through the compound control's
interface.
We could:
- Get the new property/event into official Gambas: most of the time not an
option because of application-specific-ness and we actually don't want to
tell our readers to wait for the next stable release to be able to test
our projects;
- Copy the class from gb.form into our projects and change them as we want:
possible but not very clean and especially unsatisfying if you consider
that the Gambas interpreter allows you to override classes; or
- Use CompoundControl.Children and the Control.Name attribute to walk
recursively through the children to get the right control, like with my
last resort routine:
Private Sub Discover(h As Container)
Dim g As Control
For Each g In h
Print g
If g Is Container Then Discover(g)
Next
End
I'd also like to avoid this one.
If I'm not mistaken C++ has a way around this called "protected". The
gb.form writer could make all the child controls protected so we can
inherit/override the compound control and immediately have everything
presented to us.
@Benoit: IIRC you don't want Gambas' object orientation to be as convoluted
as in C++. This protected thing doesn't sound as it would have too far-
reaching consequences, though.
Thoughts?
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list