PDA

View Full Version : is this example destinated for a class for converting into thinbasic?



largo_winch
31-01-2013, 19:31
this code example I've found from freebasic manual. I'm only asking if this example has to be translated as class/method ? or there's another way (oop like) to convert this example?


' Empty GUI script created on 01-31-2013 13:26:32 by (thinAir)
Uses "console"


Type sample


Texty As String


Declare Constructor ()
Declare Constructor ( a As Integer )
Declare Constructor ( a As Single )
Declare Constructor ( a As String, b As Byte )


Declare Operator Cast () As String
End Type


Constructor sample ()
Print "Konstruktor sample ()"
Print
THIS.Texty = "Leer"
End Constructor


Constructor sample ( a As Integer )
Print "Konstruktor sample ( a As Integer )"
Print " a = "; a
Print
THIS.Texty = Str(a)
End Constructor


Constructor sample ( a As Single )
Print "Konstruktor sample ( a As Single )"
Print " a = "; a
Print
THIS.Texty = Str(a)
End Constructor


Constructor sample ( a As String, b As Byte )
Print "Konstruktor sample ( a As String, b As Byte )"
Print " a = "; a
Print " b = "; b
Print
THIS.Texty = Str(a) + "," + Str(b)
End Constructor




Operator sample.Cast () As String
Return THIS.Texty
End Operator


Print "Erstelle x1" ' (build x1)
Dim x1 As sample


Print "Erstelle x2" ' (build x2)
Dim x2 As sample = 1


Print "Erstelle x3" ' (build x3)
Dim x3 As sample = 99.9


Print "Erstelle x4" ' (build x4)
Dim x4 As sample = sample( "aaa", 1 )


Print "Values:"
Print " x1 = "; x1
Print " x2 = "; x2
Print " x3 = "; x3
Print " x4 = "; x4
'Sleep
WaitKey




bye, largo

ErosOlmi
31-01-2013, 23:11
thinBasic has no OOP constructs so you must go with usual procedural programming way

Uses "console"

Type sample
Texty As String
End Type

PrintL "Erstelle x1" ' (build x1)
Dim x1 As sample

PrintL "Erstelle x2" ' (build x2)
Dim x2 As sample
x2.Texty = 1

PrintL "Erstelle x3" ' (build x3)
Dim x3 As sample
x3.Texty = 99.9

PrintL "Erstelle x4" ' (build x4)
Dim x4 As sample
x4.Texty = "aaa" & "," & 1

PrintL "Values:"
PrintL " x1 = ", x1.Texty
PrintL " x2 = ", x2.Texty
PrintL " x3 = ", x3.Texty
PrintL " x4 = ", x4.Texty
'Sleep
WaitKey

peter
01-02-2013, 14:06
In comparison to this OOP crap, your demo is a blessing!
Well done, Eros.

largo_winch
05-02-2013, 19:28
thank you eros for your answer, never I've seen before such a silly construct like in freebasic for shorten and cutting so simple into thinbasic! :) bye, largo

ErosOlmi
05-02-2013, 19:43
I think that FreeBasic example was not created to complicate something simple but to show how to construct a FreeBasic Class with different Constructors overloading and class casting.

Is indeed quite interesting and shows of a possible way to implement OOP.