what about the classes?

Post

Posted
Rating:
#1 (In Topic #570)
Avatar
Trainee
Hello guys, I wonder why there are "classes" to use … but I have no clue why they are  used and how to use them.
Sorry, I'm beginner (not in time, but in apps I already composed)
And I'm not English, so please bare that in mind ….  :)  :)
Thanks
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

vito49 said

Hello guys, I wonder why there are "classes" to use … but I have no clue why they are  used and how to use them…

In Object Orientated Programming, a class is a kind of template that you can use to create a new "instance" of an "object".
Sounds scary?

When you simply draw a control Button on a form, you use the Button class code to create a new instance (new version/new Button object) of the software that manages a button. This new button object allows you to customise your button with a new name, a new text caption, new size, new colour…and so on.

If we did not have a Button class we all would have to write our own code to draw our own buttons and control how they work …we would all be re-inventing the wheel!

I'll try to come up with a simple class example with its own Methods (Functions) and Properties.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
stevedee is in the usergroup ‘Regular’
Actually, just returning to the Button class may be the best example.

Start a new GUI Gambas project, but don't draw any components on the Form, just add this code to FMain.class:-

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public myButton As Button
  4.  
  5. Public Sub Form_Open()
  6.   'create a new instance of the Button Class
  7.   'and draw it on the main form (its Parent)
  8.   myButton = New Button(FMain)
  9.   myButton.Height = 100
  10.   myButton.Width = 200
  11.   myButton.top = 50
  12.   myButton.Left = 100
  13.   myButton.Text = "OK"
  14.  
  15.  

What this code is doing is creating a new button from the existing code class called Button. We call this creating a new instance of the class Button by declaring myButton as a Button.

We can then use the Button class Properties to set size, colour, text & so on.

Is this helping?
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
I have been working on this as well. Here is an example using a class to create a list of your music collection.

The Class may seem a little complicated, but I hope you can see how this small amount of code can do so much.

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim NewAlbum As Record
  4.  
  5.   NewAlbum = New Record(Me, "Sound of Silence", "Simon & Garfunkel", "SoundOfSilence.jpeg", "60s Pop")
  6.   NewAlbum = New Record(Me, "Paranoid", "Black Sabbath", "Paranoid.jpeg", "Heavy Metal")
  7.   NewAlbum = New Record(Me, "Carpenters", "Carpenters", "Carpenters.jpeg", "Pop")
  8.  

<IMG src="https://www.cogier.com/gambas/ClassExample.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
the carpenters ??? really ??? ;)
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Guru
cogier is in the usergroup ‘Guru’

PJBlack said

the carpenters ??? really ??? ;)
Really!! :D  :D
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
stevedee is in the usergroup ‘Regular’

cogier said

PJBlack said

the carpenters ??? really ??? ;)
Really!! :D  :D

…he's only just begun
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
yeah … party  :D

back to topic:
charlie … i'm an f***ing old procedural programmer with big fears of OOP for a long time and it tokks me a lot of hard work to get into it … but while understanding how it works or maybe how i should work i will say "oh wow … how could i program without that" … taking your second example a newbie would likely say "oh hell …" but yes it shows what a class can be

vito:
fight your way trough … programing is fun and you will find solutions for problems that you won't have without programing ;)

you may like to have a look here:

https://gambas-buch.de/dwen/doku.php?id=start

for years now hans lehmann wrote on that and for a starter it is very helpfully, most of it should be in english but also avail in german … i you have any questions the carpenters and the rest here will try to help you :)
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
…he's only just begun

I'm beginning to feel unwell :oops:
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
stevedee is in the usergroup ‘Regular’
Further reading from 12 months ago: Gambas One - Gambas ONE
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

…he's only just begun

I'm beginning to feel unwell :oops:

Don't feel bad Charlie.
Just sing , sing a song
because we long to be ,,,
close to you….


aaaaaaah aaaaaaah aaah
close to you
;)
Online now: No Back to the top
1 guest and 0 members have just viewed this.