ReneMiner
01-10-2014, 11:00
imagine the following, you have some standard-vartype as byte, long, dword and want to give it functions...
so it's like an udt-variable that has no further udt-elements but can have functions so it's not required to create an additional list of subitems that have to be part of the variables name then
???
maybe like this
' you know what this does:
Alias Dword As DataPtr
' ???
' but now imagine this simple example:
Type Alias DWord As DataPtr ' means this Type DataPtr consists of one Dword only
' only functions allowed here !!!
' - but statics were thinkeable... ;)
GetData As Function
SetData As Function
End Type
Function DataPtr.GetData() As String
Return Heap_Get(Me)
End Function
Function DataPtr.SetData(Byval sData as String) As Boolean
If Heap_Size(Me) Then Heap_Free(Me)
If StrPtrLen(StrPtr(sData)) Then
Me = Heap_AllocByStr(sData)
Function = (Me <> 0 )
Else
Me = 0
Function = True
Endif
End Function
' lot's of ideas for this...
' examples:
Dim myPtrs(Expression) as DataPtr [At ...]
Type t_XYZ
pData as DataPtr
'...
End Type
Type Alias TBGL_tRGBA As myColor ' would built-in udt work too?
'...
End Type
Type myStuff Extends DataPtr ' also a nice one then...
'...
End Type
Type Alias Long As Windowstate ' should be simple then
Minimize As Function
Maximize As Function
'...
End Type
Type Alias String As Username ' could be a little tricky with strings...
'...
End Type
Type Alias String As Password ' but user can use either StrPtr(Me) etc.
'... or heap could help out here to store these
End Type
and we could have built-in-vartypes that have user-definded functions.... think of the possibilities - each variable could behave different by itself... :)
currently there's some "workaround" since it does not work using "Me" without ".pData" do some overlay at me
see below (runs)
Uses "console"
Type t_DataPtr
'since simply
' Dword '<<< will ERROR
pData As DWord ' this is just to occupy the space but never used as such...
SetData As Function
GetData As Function
End Type
Function t_DataPtr.GetData() As String
Local lPtr As DWord At VarPtr(Me)
Return HEAP_Get(lPtr)
End Function
Function t_DataPtr.SetData(ByVal sData As String) As Boolean
Local lPtr As DWord At VarPtr(Me)
If HEAP_Size(lPtr) Then HEAP_Free(lPtr)
If StrPtrLen(StrPtr(sData)) Then
lPtr = HEAP_AllocByStr(sData)
Function = ( lPtr <> 0 )
Else
lPtr = 0
Function = TRUE
EndIf
End Function
Dim x As t_dataptr
If x.setData("this test") Then
PrintL x.GetData() & " was successful"
Else
PrintL "test failed"
EndIf
WaitKey
not just for storing dataptrs and data at heap but also to have variables that may limit themselves or react on certain actions under certain circumstances.
Edit:
maybe no alias but just
Type As Long t_Windowstate
Minimize As Function
'...
End Type
:confused:
so it's like an udt-variable that has no further udt-elements but can have functions so it's not required to create an additional list of subitems that have to be part of the variables name then
???
maybe like this
' you know what this does:
Alias Dword As DataPtr
' ???
' but now imagine this simple example:
Type Alias DWord As DataPtr ' means this Type DataPtr consists of one Dword only
' only functions allowed here !!!
' - but statics were thinkeable... ;)
GetData As Function
SetData As Function
End Type
Function DataPtr.GetData() As String
Return Heap_Get(Me)
End Function
Function DataPtr.SetData(Byval sData as String) As Boolean
If Heap_Size(Me) Then Heap_Free(Me)
If StrPtrLen(StrPtr(sData)) Then
Me = Heap_AllocByStr(sData)
Function = (Me <> 0 )
Else
Me = 0
Function = True
Endif
End Function
' lot's of ideas for this...
' examples:
Dim myPtrs(Expression) as DataPtr [At ...]
Type t_XYZ
pData as DataPtr
'...
End Type
Type Alias TBGL_tRGBA As myColor ' would built-in udt work too?
'...
End Type
Type myStuff Extends DataPtr ' also a nice one then...
'...
End Type
Type Alias Long As Windowstate ' should be simple then
Minimize As Function
Maximize As Function
'...
End Type
Type Alias String As Username ' could be a little tricky with strings...
'...
End Type
Type Alias String As Password ' but user can use either StrPtr(Me) etc.
'... or heap could help out here to store these
End Type
and we could have built-in-vartypes that have user-definded functions.... think of the possibilities - each variable could behave different by itself... :)
currently there's some "workaround" since it does not work using "Me" without ".pData" do some overlay at me
see below (runs)
Uses "console"
Type t_DataPtr
'since simply
' Dword '<<< will ERROR
pData As DWord ' this is just to occupy the space but never used as such...
SetData As Function
GetData As Function
End Type
Function t_DataPtr.GetData() As String
Local lPtr As DWord At VarPtr(Me)
Return HEAP_Get(lPtr)
End Function
Function t_DataPtr.SetData(ByVal sData As String) As Boolean
Local lPtr As DWord At VarPtr(Me)
If HEAP_Size(lPtr) Then HEAP_Free(lPtr)
If StrPtrLen(StrPtr(sData)) Then
lPtr = HEAP_AllocByStr(sData)
Function = ( lPtr <> 0 )
Else
lPtr = 0
Function = TRUE
EndIf
End Function
Dim x As t_dataptr
If x.setData("this test") Then
PrintL x.GetData() & " was successful"
Else
PrintL "test failed"
EndIf
WaitKey
not just for storing dataptrs and data at heap but also to have variables that may limit themselves or react on certain actions under certain circumstances.
Edit:
maybe no alias but just
Type As Long t_Windowstate
Minimize As Function
'...
End Type
:confused: