start method in class

Post

Posted
Rating:
#1 (In Topic #868)
Trainee
Hi, I try to use a Gambas-Class (not a Form) as starting class. I added "Public Sub Main() ...", but Gambas says "No starting method". How to do this? Thanks!
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
 Try using a Module, not a class. If you still can't get it to work, post the code, so we can have a look.
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Must be a class to use the Application_Error event
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Have you right clicked the class in the left column and set it as startup class?
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
 Don't use Main() for a class.
Use _init() or _new()
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
neither _init() nor _new()
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
vuott is in the usergroup ‘Regular’

paco said

Must be a class to use the Application_Error event
A Module does not have and cannot raise its own Events, but it can raise Events of other Classes.

Exemplum:

Code (gambas)

  1. ' Gambas module file
  2.  
  3. Public Sub Main()
  4.  
  5.  
  6. ' By displaying the console and pressing the "Enter" key on the keyboard this Event of the "Application" Class will be raised:
  7. Public Sub Application_Read()
  8.  
  9.   Quit
  10.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#8
Trainee
 yes vuott, but I think it's the interpreter that fires the Application_Error in the starting class
Online now: No Back to the top

Post

Posted
Rating:
#9
Trainee
 Ok that works. But it's nothing else than an Event-Handler in a module - very confusing.
My simple starting question was, how to use a class as starting-class - Gambas offers this option in it's project-tree. Is there a way?
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’
In my opinion Gambas, to start a "command line" application, looks for the main module "Main.module"; instead, to start an application in a graphical environment (GTK or QT), it looks for the main class "FMain.class".
Therefore, I believe it is not possible to start Gambas "directly" from a specific secondary Class, created by you.
I believe that the correct procedure is to create an instance of the specific secondary Class in the Main Class or in the Main Module of the application (in the startup Class or Module) and in those to invoke a routine of the specific secondary Class that you created.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’
Why does your class HAVE to be the startup ?
Can you not just make a Startup.module then have it load the class?

Code (gambas)

  1. ' Gambas module file
  2.  
  3. Public Sub Main()
  4.  
  5.   Class.Load("MyStartingClass")
  6.  
  7.  

Or…

Code (gambas)

  1. ' Gambas module file
  2.  
  3. Public Sub Main()
  4.  
  5.   MyStartingClass.Run
  6.  
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#12
Guru
BruceSteers is in the usergroup ‘Guru’
 It's kinda badly named isn't it ?

Setting the "Startup class"
(but sorry you can't use a class just a module ! lol)
Online now: No Back to the top

Post

Posted
Rating:
#13
Guru
BruceSteers is in the usergroup ‘Guru’
Benoit provided the simple answer on the mailing list (bless him)…

Main() must be static

Code (gambas)

  1.  
  2.  
  3.  
Online now: No Back to the top

Post

Posted
Rating:
#14
Regular
vuott is in the usergroup ‘Regular’

BruceSteers said

Benoit provided the simple answer on the mailing list……
ok  :!:

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#15
Guru
BruceSteers is in the usergroup ‘Guru’
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.

Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. Static $myGlobalInteger As Integer
  5.  
  6.  
  7. $myGlobalInteger = 5
  8.  
  9.  
  10.  

But i could well be wrong about that.
Online now: No Back to the top

Post

Posted
Rating:
#16
Guru
BruceSteers is in the usergroup ‘Guru’
It makes more sense for your startup class/module to not really do much except initiate/run your other class files like vuott says.
Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

BruceSteers said

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.

Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. Static $myGlobalInteger As Integer
  5.  
  6.  
  7. $myGlobalInteger = 5
  8.  
  9.  
  10.  

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.

Online now: No Back to the top

Post

Posted
Rating:
#18
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

BruceSteers said

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

Online now: No Back to the top
1 guest and 0 members have just viewed this.