Put this on the beginning of a class file to tell Gambas that the current class inherits the ParentClass class.
What is inherited ?
The class inherits from its parent every method, property, constant and event.
Which class can be a parent class ?
You can inherited any class, even a native one!
For example, you can create
a custom MyListBox
class that inherits ListBox
but allows association a tag with each list item.
Note that you can't use INHERITS
in a form class file, because forms already
inherits the Form class!
Inheritance and constructor
Contrary to all the object 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:
aMyListBox = NEW MyListBox ( "Name", aContainer )