<!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 - NEW
</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="../lang+en">Up</a>&nbsp;
<a href="move+en">Previous</a>&nbsp;
<a href="new2+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
NEW
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><u>Object</u> <b>= NEW</b> <u>Class</u> [ <b>(</b> <u>Constructor parameters</u>... <b>)</b> ] [ <b>AS</b> <u>Name</u> ]</pre><p>

Instantiates the class <u>Class</u>.
<p>
The <a href="../def/object+en">object</a> or class where the <a href="../def/object+en">object</a> is instantiated is its parent.
<p>
If a name is specified, the new <a href="../def/object+en">object</a> will be able to raise events by calling a public procedure or function in its parent. The name of this  event handler is  the name of the <a href="../def/object+en">object</a> followed by an underscore and the name of the event.
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/info.png" align="center"></td><td valign="top">
<tt><b>NEW</b></tt> is not an operator. You can only use it within an assignment.
<p>
But you can use the <a href="new2+en">New</a> function instead.
</td></tr></table></div>
<p>
Two different objects can have the same event name. Thus, you can manage events of multiple objects in the same event procedure, provided these objects raise the same events.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">hButton = NEW Button(ME) AS &quot;MyButton&quot;

...

PUBLIC PROCEDURE MyButton_Click()

  PRINT &quot;My button was clicked !&quot;

END</pre>
<p>

The next example creates 9*9*9 small <a href="../comp/gb.qt/textbox+en">TextBox</a>es to which can be accesses through the public <a href="../comp/gb/object[]+en">Object[]</a> array <i>objIsImpossible</i>
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PUBLIC bIsInitialised AS Boolean
PUBLIC objIsImpossible AS Object[]

PUBLIC SUB Form_Open()
DIM iR AS Integer
DIM iR2 AS Integer
DIM iC AS Integer
DIM iC2 AS Integer
DIM iDigit AS Integer
DIM iX AS Integer
DIM objTextBox AS TextBox


IF bIsInitialised = FALSE THEN
  objIsImpossible = NEW Object[] ' Need to create the array
  iX = 0
  FOR iR = 0 TO 8
    FOR iC = 0 TO 8
      FOR iDigit = 0 TO 8
        iR2 = iDigit MOD 3
        iC2 = iDigit / 3
        objTextBox = NEW TextBox(ME) ' create the next of the 9*9*9 TextBox -es
        objTextBox.X = (iR * 3 + iR2) * 12 + 2
        objTextBox.y = (iC * 3 + iC2) * 12 + 2
        objTextBox.Width = 10
        objTextBox.Height = 10

        objIsImpossible.Add(objTextBox, iX)

        iX = iX + 1
      NEXT '  iDigit
    NEXT '    iC
  NEXT '      iR
ENDIF
END</pre>
<p>

<hr><b>See also</b><br>
<a href="../cat/object+en">Object &amp; Class Management</a>&nbsp; <a href="../cat/event+en">Event Management</a>&nbsp; <a href="new2+en">New</a>&nbsp;

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

