[Gambas-user] define a startup class?

Benoit Minisini gambas at ...2...
Mon May 19 10:48:58 CEST 2003


Le Lundi 19 Mai 2003 06:16, Rob a écrit :
> On Sunday 18 May 2003 23:53, Ed Weinberg wrote:
> > I am a Gambas nubee.
> > How do I
> > "define a startup class in the project properties dialog" called Main or
> > something like that?  Troubleshooting says that I need to do that to get
> > it to run, but does not tell me how.
>
> You can go into the Project menu, then Properties, then on the General tab
> scroll down a bit and you'll find the startup class option.  Set it to the
> class for your startup form.
>
> That's not all you have to do though.  In VB, if you select a startup form,
> it's automatically loaded and shown at runtime.  In Gambas, the only
> special thing about the startup class is that it contains a public sub
> called Main() which gets executed first.  Into that sub you need to put
> something like the following (a Gambas idiom, basically):
>
> DIM testform AS NEW testform
> testform.show
>
> or if you want to be object-orientedly-correct and less VB-like:
>
> DIM myTestForm as new testform
> myTestForm.show
>
> The first line loads the form (which would automatically happen in VB the
> first time you referred to it as an object) and the second shows it (which
> only automatically happens in VB if the form is the startup form.)  There
> is a "load components immediately at startup" option in project properties
> but that doesn't seem to make the above code unnecessary yet.  This may be
> because VB forms have a class built into them whereas Gambas keeps the
> class separate from the form layout, but I haven't looked too closely yet.
>

When you have a form named Form1 in VB, and you type Form1.Show, what happens 
in the background ? Exactly what you must do by hand in Gambas: the form is 
instanciated, and the instance is given the same name as the form.

This leads to problems:

1) The newbie is confused, because class and instance of this class have the 
same name. So the newbie don't really understand what he does exactly.

2) The form is instanciated when you try to use the form class as a form 
instance. You save two lines of code and one variable at first, but when you 
want to exit the program, you must be very careful not to make a reference to 
a closed form, elsewhere this form is recreated, and your program does not 
exit ! (I had this problem many times in my VB programs)

Maybe I could have the same behavior with forms on Gambas. But I think that 
the disadventages are greater than the advantages.

> I'm hoping to hack the IDE to hide some of this and make some of it
> automatic, maybe even provide an option to emulate the VB startup form
> behavior and hide Sub Main in that case.  I know this is contrary to what
> Benoit wants to do (make a VB like language that Linux people won't sneer
> at too badly) but I'll probably submit the patches anyway when things are
> working just in case.
>
> Rob
>

Modifying the IDE will not help you... It is a functionnality that must be add 
to the interpreter: something like auto-instanciating class. But I don't even 
know if it is technically possible at the moment !

Maybe I could add a method to the Form class: Form.ShowDialog, that will 
automatically create an instance, and open it modal. But it need support into 
the interpreter too...

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list