PDA

View Full Version : Allow Me without dot or Extends <PrimitiveType>



ReneMiner
08-11-2015, 14:39
Once more I'm in the need of something like this:

for <primitive> insert any of these:
Byte, Word, Integer, Boolean, DWord, Long, Single, Double, Extended, Ext [, String [ * Size]]



' currently:
Type tType
myVal As <primitive>

Static whatever As Number

Function _Create(Byval myVal As <primitive>)
Me.myVal = myVal
End Function
' this Type now only has 1 Subelement of Type <primitive>
' SizeOf(tType) equals SizeOf(<primitive>)
' omit something that follows below here...
End Type

Dim X As tType(123)



now there are 2 ways for a solution:

the simple one:

Me or the variablename of tType to use without . (dot, followed by { Static-name | Function-Name})
should refer to the first udt-subelement (thats Varptr equals the pointer to the variable itself of course...)
so it would be valid to use X as well as X.myVal in the example above

more complicated:


Type tType Extends <primitive>

Static whatever As Number

Function _Create(Byval myVal As <primitive>)
Me = myVal
' Me gets treated like <primitive>
End Function

Function GetVal() As <primitive>
Function = Me
End Function

Function SetVal(Byval myVal As <Primitive>) As <primitive>
Me = myVal
Function = Me
End Function

Function AddVal(Byval myVal As <Primitive>) As <primitive>
' If <Primitive> = STRING * SIZE Then
' --- would work different (add up all bytes values perhaps???)
' Else
Me += myVal
' Endif
Function = Me
End Function
End Type

Dim X As tType(123) ' almost equals: Dim X As <primitive> Value 123

' the difference is that X as tType is able to have functions & statics, so one can use for example:
' X gets treated like <primitive>
X = 123
' should equal
X.SetVal(123)

X += 123
' equals then
X.AddVal(123)

PrintL X
' should equal the output for
PrintL X.GetVal()





It is not allowed to have any other UDT-subelements butStatic's and Function's when Extends <primitive>.
Assigning and getting the value works like if it were a normal variable of type <primitive>.

If another Type extends the extended <primitive>, the use of only Me or the variables name without
. (dot) followed by { Static-name | Function-Name} should still work like it were a variable of <primitive>.

ErosOlmi
10-11-2015, 22:02
Ciao René,

I think your idea is too much advanced for the OOP level thinBasic actually is.
We need to make a lot of intermediate steps before being able to develop something like the one you suggested that in OOP is called something like Generics: https://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx

Actually I'm working on the possibility to add any data type (static and dynamic) inside TYPEs.
I think if I will succeed on this, a lot of new possibilities will be discovered.

Sorry but I cannot see any way to develop your request at the moment.

Ciao
Eros