start method in class

New to Gambas? Post your questions here. No question is too silly or too simple.
paco
Posts: 15
Joined: Friday 11th February 2022 5:42pm

start method in class

Post by paco »

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!
User avatar
cogier
Site Admin
Posts: 1125
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: start method in class

Post by cogier »

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.
paco
Posts: 15
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco »

Must be a class to use the Application_Error event
User avatar
BruceSteers
Posts: 1565
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

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
User avatar
BruceSteers
Posts: 1565
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: start method in class

Post by BruceSteers »

Don't use Main() for a class.
Use _init() or _new()
If at first you don't succeed , try doing something differently.
BruceS
paco
Posts: 15
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco »

neither _init() nor _new()
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: start method in class

Post by vuott »

paco wrote: Sunday 10th July 2022 7:38pm 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:
' 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.
paco
Posts: 15
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco »

yes vuott, but I think it's the interpreter that fires the Application_Error in the starting class
paco
Posts: 15
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco »

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?
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: start method in class

Post by vuott »

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 !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply