* How to make an Array of a selfdefined datatype
* The Program
* The Code:
* Fmain.class
* CCar.class
* The Source
The easy Gambas Doku
Each Array is of a special datatype.
If you define a class, this class is like a datatype and an object of this class has got this datatype.
You can create an array in which you can put objects of your class, to do so define the array like this:
var_name AS Object[]
At starttime three objects of the class CCar are instanciated by the constructor.
The objects are added to the array.
If you click the button, the brand of each object will be displayed.
$arCar AS Object[]
$blue AS CCar
$red AS CCar
$green AS CCar
STATIC PUBLIC SUB Main()
hForm AS Fmain
hForm = NEW Fmain
hForm.show
END
PUBLIC SUB _new()
$blue = NEW CCar("blueCar", 300, 400.34)
$red = NEW CCar("redCar", 200, 300.56)
$green = NEW CCar("greenCar", 100, 200.34)
$arCar = NEW Object[]
$arCar.Add($blue)
$arCar.Add($red)
$arCar.Add($green)
END
PUBLIC SUB Button1_Click()
i AS Integer
txt AS String
FOR i = 0 TO 2
txt = txt & $arCar[i].getBrand() & "<br>"
NEXT
TextLabel1.Text = txt
END
Download
Referenced by :