start method in class

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

start method in class

Post by paco » Saturday 9th July 2022 9:08pm

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: 896
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: start method in class

Post by cogier » Sunday 10th July 2022 2:15pm

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: 9
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco » Sunday 10th July 2022 7:38pm

Must be a class to use the Application_Error event

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

Re: start method in class

Post by BruceSteers » Sunday 10th July 2022 7:43pm

Have you right clicked the class in the left column and set it as startup class?

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

Re: start method in class

Post by BruceSteers » Sunday 10th July 2022 7:45pm

Don't use Main() for a class.
Use _init() or _new()

paco
Posts: 9
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco » Sunday 10th July 2022 8:27pm

neither _init() nor _new()

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

Re: start method in class

Post by vuott » Sunday 10th July 2022 10:03pm

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
I am a European.

Amare memorentes atque deflentes ad mortem silenter labimur.

paco
Posts: 9
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco » Sunday 10th July 2022 10:11pm

yes vuott, but I think it's the interpreter that fires the Application_Error in the starting class

paco
Posts: 9
Joined: Friday 11th February 2022 5:42pm

Re: start method in class

Post by paco » Sunday 10th July 2022 10:33pm

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

Re: start method in class

Post by vuott » Sunday 10th July 2022 10:53pm

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.
I am a European.

Amare memorentes atque deflentes ad mortem silenter labimur.

Post Reply