[Gambas-user] Class startup?
Tobias Boege
taboege at ...626...
Thu May 18 15:13:30 CEST 2017
On Thu, 18 May 2017, alexchernoff wrote:
> Good day all,
>
> is there a way to have a routine execute in a class as soon as a new
> instance of it is created? I have a Public Sub Main() but it doesn't seem to
> run.
>
> I come to Gambas from Xojo and there classes have a Constructor() sub which
> runs on init.
>
> thanks!
>
The constructor is called _new in Gambas (see [1]):
Public Sub _new()
' runs on object creation
End
You can also specify parameters to the _new() method like
' In MyClass.class:
Public Sub _new(X As Integer)
' ...
End
which demands that an Integer be given on object instantiation:
Dim h As New MyClass(10) ' X = 10
Regards,
Tobi
[1] http://gambaswiki.org/wiki/cat/special
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list