/ def / object
object
An object is a data structure that provides properties, variables, methods and events.

Each object is associated with a class, that describes the behaviour of these properties, variables, methods and events.

A class may be defined either in Gambas as e.g. the class "TextBox" or by the programmer who defines a new class in its project.

A class never has an address. A class cannot be displayed.

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.

## Examples

In this example "TextBox" is a class. "TextBox1" is an object, which is created by the IDE. "hTextBox1" is a reference to an object of the type TextBox. Later in this example the reference to the IDE created "TextBox1" is copied to "hTextBox1". 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.

Expression | Value
--- | ---
TextBox | ERROR: Unknown ...
TextBox1 | (TextBox 0x81099c0)
hTextBox1 | (TextBox 0x81099c0)
hTextBox1.Text | "Set hTextBox1"

    PUBLIC SUB Button1_Click()

      DIM hTextBox1 AS TextBox            ' can hold the address of the object

      hTextBox1 = TextBox1                ' gets the address of the already existing object
      hTextBox1.Text = "Set hTextBox1"
      hTextBox1.X = TextBox1.X + 80
      hTextBox1.Y = TextBox1.Y + 120

    END

In this example "TextBox" is a class. "hTextBox1" is an object of this class, which will be created new on the Form Form1. And then filled with a Text and moved to a place somewhere relative to the IDE created TextBox with the name TextBox1

    PUBLIC SUB Button1_Click()

      DIM hTextBox1 AS TextBox            ' can hold the address of the object

      hTextBox1 = NEW TextBox(Form1)      ' Instantiates a new TextBox, i.e. creates the object
      hTextBox1.Text = "Set hTextBox1"
      hTextBox1.X = TextBox1.X + 80
      hTextBox1.Y = TextBox1.Y + 120

    END