Page 2 of 2

Re: start method in class

Posted: Monday 11th July 2022 11:17am
by BruceSteers
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

Re: start method in class

Posted: Monday 11th July 2022 11:19am
by BruceSteers
It's kinda badly named isn't it ?

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

Re: start method in class

Posted: Monday 11th July 2022 11:48am
by BruceSteers
Benoit provided the simple answer on the mailing list (bless him)...

Main() must be static

Static Public Sub Main()

End

Re: start method in class

Posted: Monday 11th July 2022 2:36pm
by vuott
BruceSteers wrote: Monday 11th July 2022 11:48am Benoit provided the simple answer on the mailing list......
ok :!:

Re: start method in class

Posted: Monday 11th July 2022 3:01pm
by BruceSteers
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.

Re: start method in class

Posted: Monday 11th July 2022 3:07pm
by BruceSteers
It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.

Re: start method in class

Posted: Thursday 14th July 2022 3:10am
by thatbruce
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.

Re: start method in class

Posted: Thursday 14th July 2022 3:14am
by thatbruce
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