<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - INHERITS
</title>
</head>
<body>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help%3Fen"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;&nbsp;
<a href="../lang%3Fen">Up</a>&nbsp;&nbsp;
<a href="inc%3Fen">Previous</a>&nbsp;&nbsp;
<a href="input%3Fen">Next</a>&nbsp;&nbsp;
</td></tr></table>
<div class="notab">
<h1>
INHERITS
</h1>
<div class="black"><font color="white" size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>INHERITS</b> <u>ParentClass</u></pre><p>

Put this on the beginning of a class file to tell <a href="../def/gambas%3Fen">Gambas</a> that
the current class inherits the ParentClass class.
<p>
<h2>What is inherited ?</h2>
<p>
The class inherits from its parent every method, property, constant
and event.
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/warning.png" align="center"></td><td valign="top">
You must use the <a href="me%3Fen">ME</a> keyword to access the inherited elements from the class inside.
</td></tr></table></div>
<p>
<h2>Which class can be a parent class ?</h2>
<p>
You can inherited any class, even a native one!
<p>
For example, you can create
a custom MyListBox class that inherits <a href="../comp/gb.qt/listbox%3Fen">ListBox</a>
but allows to associate a tag with each list item.
<p>
Note that you can't use <tt><b>INHERITS</b></tt> in a form class file, because forms already
inherits the <a href="../comp/gb.qt/form%3Fen">Form</a> class!
<p>
<h2>Virtual dispatching</h2>
<p>
When calling a method or accessing a property from an object refernce, <a href="../def/gambas%3Fen">Gambas</a> always
use <i>virtual dispatching</i>. It means that the real class of the object is always used, and
not the type of the variable that references the object - As it was in <a href="../def/gambas%3Fen">Gambas</a> 1.0.
<p>
<h2>Inheritance and constructor</h2>
<p>
Contrary to all the object language I know, each class in the inheritance
hierarchy consumes the parameters passed to the constructor.
<p>
Let's suppose we have the following inheritance tree:
<p>
MyListBox ---inherits--> <a href="../comp/gb.qt/listbox%3Fen">ListBox</a> ---inherits---> <a href="../comp/gb.gtk/control%3Fen">Control</a>
<p>
<ul>
<li><a href="../comp/gb.gtk/control%3Fen">Control</a>._new() does not exist.
<li><a href="../comp/gb.qt/listbox%3Fen">ListBox</a>._new() takes one parameter: the parent control.
<li>MyListBox._new() takes one parameter: a name - It is just an example.
<p>
</ul>

So <tt><a href="new%3Fen">NEW</a> MyListBox</tt> will take two parameters.
<p>
<ul>
<li>The first will be sent to MyListBox._new().
<li>The second to <a href="../comp/gb.qt/listbox%3Fen">ListBox</a>._new().
<p>
</ul>

But the <a href="../comp/gb.qt/listbox%3Fen">ListBox</a>._new() will be called first. This way, you are sure that the <a href="../comp/gb.qt/listbox%3Fen">ListBox</a> control exists
when you are in MyListBox._new().
<p>
You will create a MyListBox control this way:
<p>
<tt>aMyListBox = <a href="new%3Fen">NEW</a> MyListBox ( &quot;Name&quot;, aContainer )</tt>
<p>
<hr><b>See also</b><br>
<a href="../cat/object%3Fen">Object &amp; Class Management</a>&nbsp;&nbsp;

</div>
<hr>
</body>
</html>

