start method in class
start method in class
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!
- cogier
- Site Admin
- Posts: 1126
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: start method in class
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.
Re: start method in class
Must be a class to use the Application_Error event
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: start method in class
Have you right clicked the class in the left column and set it as startup class?
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: start method in class
Don't use Main() for a class.
Use _init() or _new()
Use _init() or _new()
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: start method in class
neither _init() nor _new()
Re: start method in class
A Module does not have and cannot raise its own Events, but it can raise Events of other Classes.
Exemplum:
' Gambas module file
Public Sub Main()
End
' By displaying the console and pressing the "Enter" key on the keyboard this Event of the "Application" Class will be raised:
Public Sub Application_Read()
Quit
End
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
Re: start method in class
yes vuott, but I think it's the interpreter that fires the Application_Error in the starting class
Re: start method in class
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?
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?
Re: start method in class
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.
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 !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.