Did you know?

Post your Gambas programming questions here.
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Did you know?

Post by cogier »

I must have typed 'Open_Form' quite a few times to complete the 'Public Sub Form_Open()', then I discovered that this can be automatically created by double clicking the Form.

I suspect you all knew this but I thought I would share this anyway.
User avatar
gbWilly
Posts: 68
Joined: Friday 23rd September 2016 11:41am
Location: Netherlands
Contact:

Re: Did you know?

Post by gbWilly »

There is more of that:
For example, just try double clicking a button on a form.
You'll be in the code editor of that forms class at the Public Sub Button_Click() event with the cursor positioned ready to code.
I use it all the time...

OR

On a form or any control right-click and go to menu item 'events', and click the event you want to code.
Code editor will open the forms class and your event is declared and cursor positioned ready to code.

The Gambas IDE really is one of the best IDE's I have ever used and I'm sure I haven't discovered all of its features ;)
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer


... there is always a Catch if things go wrong!
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Did you know?

Post by jornmo »

I did :)

Have you tried typing ps+ tab? Or v + tab? Or _n +tab?
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

I knew most of these but for variables I use: -
ds [Tab]
df [Tab]
di [Tab]

[Ctrl] + [Alt] + [Enter] from here http://gambas.8142.n7.nabble.com/Questi ... 58228.html is also interesting.

When do you use '_n'?
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Did you know?

Post by jornmo »

_n is the equivalent of a constructor in other languages. It sort of initialises an object when it is created, i.e. it is called each time you use the NEW keyword.
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

Can you give me an example of a 'Constructor' as the information out there is way beyond me!
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Did you know?

Post by jornmo »

How is your understanding of object oriented programming?
A class file in Gambas represents the blue print of an object, while a module file represents a static class.
When you've made a class in Gambas, you can create objects from it with

Code: Select all

Private $myObject = New MyClass As "EventName"
Inside the class file, you can use special methods, amongst:

Code: Select all

Public Sub _new()
  ...
End
The code inside this block is executed each time a new object is created. If the class is a graphical control, it would make sense to set the default size, colors and the like in this block.
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

I have discovered another short cut I didn't know about.

If you hold down the [Ctrl] key and click on a Gambas reserved word (e.g. Public, New, For, etc) the relevant help page is displayed.

But you all knew that didn't you?
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Did you know?

Post by jornmo »

I might have tried it a long time ago since it is the same in Lazarus, but I prefer F2. F2 does the same thing - shows help on Gambas stuff, and takes you to the declaration on other stuff :)
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

I have found another little gem I thought I would pass on (even though you know it already!)

Open preferences [Ctrl]+[Alt]+P and switch on Local variable automatic declaration then in your empty 'Sub' type iCount = 6 and hey presto a Dim iCount as Integer automatically appears!
Post Reply