start method in class

New to Gambas? Post your questions here. No question is too silly or too simple.
BruceSteers
Posts: 841
Joined: Thursday 23rd July 2020 5:20pm

Re: start method in class

Post by BruceSteers » Monday 11th July 2022 11:17am

Why does your class HAVE to be the startup ?
Can you not just make a Startup.module then have it load the class?
' Gambas module file

Public Sub Main()
  
  Class.Load("MyStartingClass")
  
End
Or...
' Gambas module file

Public Sub Main()
  
  MyStartingClass.Run
  
End

BruceSteers
Posts: 841
Joined: Thursday 23rd July 2020 5:20pm

Re: start method in class

Post by BruceSteers » Monday 11th July 2022 11:19am

It's kinda badly named isn't it ?

Setting the "Startup class"
(but sorry you can't use a class just a module ! lol)

BruceSteers
Posts: 841
Joined: Thursday 23rd July 2020 5:20pm

Re: start method in class

Post by BruceSteers » Monday 11th July 2022 11:48am

Benoit provided the simple answer on the mailing list (bless him)...

Main() must be static

Static Public Sub Main()

End

vuott
Posts: 120
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: start method in class

Post by vuott » Monday 11th July 2022 2:36pm

BruceSteers wrote:
Monday 11th July 2022 11:48am
Benoit provided the simple answer on the mailing list......
ok :!:
I am a European.

Amare memorentes atque deflentes ad mortem silenter labimur.

BruceSteers
Posts: 841
Joined: Thursday 23rd July 2020 5:20pm

Re: start method in class

Post by BruceSteers » Monday 11th July 2022 3:01pm

I'm guessing the whole class should then have to be static too?
and any global variables referenced from Main() would need to be declared as static too.
' Gambas class file

Create Static 

Static $myGlobalInteger As Integer

Static Public Sub Main()

$myGlobalInteger = 5

End

But i could well be wrong about that.

BruceSteers
Posts: 841
Joined: Thursday 23rd July 2020 5:20pm

Re: start method in class

Post by BruceSteers » Monday 11th July 2022 3:07pm

It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.

User avatar
thatbruce
Posts: 31
Joined: Saturday 4th September 2021 11:29pm

Re: start method in class

Post by thatbruce » Thursday 14th July 2022 3:10am

BruceSteers wrote:
Monday 11th July 2022 3:01pm
I'm guessing the whole class should then have to be static too?
and any global variables referenced from Main() would need to be declared as static too.
' Gambas class file

Create Static 

Static $myGlobalInteger As Integer

Static Public Sub Main()

$myGlobalInteger = 5

End

But i could well be wrong about that.
Perhaps ;) Reread the first bit of the Create Static help till yours eyes bleed (and then tell me what it means :( )
I have only ever had one case where I had to use that command. Don't ask, I have no idea why.

User avatar
thatbruce
Posts: 31
Joined: Saturday 4th September 2021 11:29pm

Re: start method in class

Post by thatbruce » Thursday 14th July 2022 3:14am

BruceSteers wrote:
Monday 11th July 2022 3:07pm
It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.
do much other than everything that you need done before your real main processing begins....
Is the internet up?
Is the database server running?
Is it Friday the 13th?

etc

Post Reply