<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - object
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../def+en">Up</a>&nbsp;
<a href="linux+en">Previous</a>&nbsp;
<a href="staticarray+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
object
</h1>
<h3>Class</h3>
A class may be defined either in <a href="gambas+en">Gambas</a> as e.g. the class &quot;<a href="../comp/gb.qt/textbox+en">TextBox</a>&quot;
or the programmer creates a new own class.
<p>
A class never has an address. A class cannot be displayed.
<p>
<h3>Object</h3>
<p>
To use a class at runtime, it must be instantiated. By this an object is created.
This is either done by the framework at start, or by the program with the <a href="../lang/new2+en">New</a> command.
<p>
In both cases some memory holds all the variables of the class.
<p>
Objects have a runtime address. This address can be displayed in the watch window.
As well members of the object can be displayed in the watch window.
<p>
<h3>Examples</h3>
<div class="box">
In this example &quot;<a href="../comp/gb.qt/textbox+en">TextBox</a>&quot; is a class.
&quot;TextBox1&quot; is an object, which is created by the IDE.
&quot;xTextBox1&quot; is a reference to an object of the type <a href="../comp/gb.qt/textbox+en">TextBox</a>.
Later in this example the reference to the IDE created &quot;TextBox1&quot; is copied to &quot;xTextBox1&quot;.
In the watch window of the IDE both references show the same hexadecimal address.
As well members of the object can be displayed in the watch window.
<p>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr><th>
Expression
</th><th>
Value
</th></tr>
<tr class="dark"><td valign="top">
<a href="../comp/gb.qt/textbox+en">TextBox</a>
</td><td valign="top">
<a href="../lang/error+en">ERROR</a>: Unknown ...
</td></tr>
<tr><td valign="top">
TextBox1
</td><td valign="top">
(TextBox 0x81099c0)
</td></tr>
<tr class="dark"><td valign="top">
xTextBox1
</td><td valign="top">
(TextBox 0x81099c0)
</td></tr>
<tr><td valign="top">
xTextBox1.Text
</td><td valign="top">
&quot;Set xTextBox1&quot;
</td></tr>
</table>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PUBLIC SUB Button1_Click()
DIM xTextBox1 AS TextBox            ' can hole the address of the object

xTextBox1 = TextBox1                ' gets the address of the already existing object
xTextBox1.Text = &quot;Set xTextBox1&quot;
xTextBox1.X = TextBox1.X + 80
xTextBox1.Y = TextBox1.Y + 120
END</pre>
</div>
<p>
<div class="box">
In this example &quot;<a href="../comp/gb.qt/textbox+en">TextBox</a>&quot; is a class. &quot;xTextBox1&quot; is an object of this class, which will be created new on the <a href="../comp/gb.qt/form+en">Form</a> Form1.
And then filled with a Text and moved to a place somewhere relative to the IDE created
<a href="../comp/gb.qt/textbox+en">TextBox</a> with the name TextBox1
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PUBLIC SUB Button1_Click()
DIM xTextBox1 AS TextBox            ' can hold the address of the object

xTextBox1 = NEW TextBox(Form1)      ' Instatiate a TextBox, create the object
xTextBox1.Text = &quot;Set xTextBox1&quot;
xTextBox1.X = TextBox1.X + 80
xTextBox1.Y = TextBox1.Y + 120
END</pre>
</div>

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

