Autore Topic: Estendere classi in componenti esistenti  (Letto 442 volte)

Online vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.724
  • Ne mors quidem nos iunget
    • Mostra profilo
Estendere classi in componenti esistenti
« il: 01 Novembre 2014, 15:02:55 »
Vi riporto questa discussione:


" 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:

Codice: gambas [Seleziona]
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
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »