INHERITS

INHERITS PatroKlaso
Metas tio cxi je komenco de dosiero klaso por informi Gambaso ke aktuala klaso heredas PatroKlaso_n.

Kio estas herdato ?

Klaso herdas gia patro cxio metodoj, atributoj, konstantoj kaj eventoj.

Vi povas uzi sxlosilvorton ME por havi antingon al herdataj elementoj en klaso.

Kiu klaso povas esti patra klaso ?

Vi povas herdati cxio klaso, ecx indigxena klaso!

Ekzamplo, vi povas krei lauxmendan MiaListBoxan klason, kiu herdas ListBox sed permesas por but allows to associate a tag with each list item.

Rimarku, ke vi ne povas uzi INHERITS en forma klasa dosiero cxar formoj jam herdatas klaso Form.

Virtuala dispatching

Kiam vokante metodo aux atingante atributo el referenco , Gambaso cxiam uzas When calling a method or accessing a property from an reference, Gambaso always use virtual dispatching. It means that the real class of the is always used, and not the type of the variable that references the - As it was in Gambaso 1.0.

Inheritance and constructor

Contrary to all the language I know, each class in the inheritance hierarchy consumes the parameters passed to the constructor.

Let's suppose we have the following inheritance tree:

MyListBox ---inherits--> ListBox ---inherits---> Control

  • Control._new() does not exist.

  • ListBox._new() takes one parameter: the parent control.

  • MyListBox._new() takes one parameter: a name - It is just an example.

So NEW MyListBox will take two parameters.

  • The first will be sent to MyListBox._new().

  • The second to ListBox._new().

But the ListBox._new() will be called first. This way, you are sure that the ListBox control exists when you are in MyListBox._new().

You will create a MyListBox control this way:

hMyListBox = NEW MyListBox("Name", hContainer)

See also