Now before i forget it/ and what was the intention (to have properties) for these to have them at an udt the way leads along that road. The array-problem has to be solved before
Now what i imagine properties are is an udt that binds where is nothing to node it. its like appending new subelements to an udt while the code is executed. i know there is something that allows to attach properties to module classes during runtime but i intend to use udts in thinBasic without the need of an external library.
Alias Type As Property
Alias _Create As _Attach
Begin Const
$NONE = ""
%NONE_definedAt = VarPtr($NONE)
End Const
' $NONE in case NOTHING to pass as parameter byref for ANYTYPE to detach
' easy to check if varptr(param) = %NONE_defined_at
Property pProtoTypeOfProperties
Static allKnownProperties As Dword ' this maybe a String or Heap
Static sizesOfPAllroperties AS Dword ' this parallel to the above
static owners As Dword ' another array / not associated to the above- holding all varptrs of anything
' that got a property attached
static proplistByOwner ' this array in same order as owners is containing pointers to long arrays
' the long-arrays (1 per ownerr) hold the indexes of all properties that were
' attached to this owner
lDistance As Long
Function _Attach(ByRef AtWhom As AnyType)
String WhatAmI = TypeOf(Me)
If WhatAmI = "UDT.PPROTOTYPEOFPROPERTIES" Then
MSGBox("ERROR - The prototype of properties itself is no property that were attachable anywhere", %MB_ICONERROR,"INVALID ASSIGNMENT")
STOP
Endif
' now its sure this is an extends'ion
if Me.AllKnownProperties = 0 then
' this one is the first to attach
' now store the type, take the pointer as first element of the array that is pointed in Me.AllKnownProperties
' what ever is typeOf(ME) has been stored as first of properties known to the prototype
Me.AllKnownProperties = Heap_AllocByStr(MKDWD$(Heap_AllocByStr(WhatAmI))
' the same do wit the size
Me.SizeOfAllProperties= Heap_AllocByStr(MKL$(SizeOf(Me)))
Else
Local pAll(Heap_Size(Me.AllKnownProperties)\4) As Dword At me.AllKnownProperties
if (Array Scan pAll Ptr, = WhatIAm )= 0 then
' what i am is not listed yet, append it
Me.AllKnownProperties=Heap_Reallocbystr( Me.AllKnownProperties, Heap_Get( Me.AllKnownProperties) & MKDWD$(Heap_AllocByStr(WhatIAm)) )
Me.SizeOfAllProperties=Heap_Reallocbystr( Me.SizeOfAllProperties, Heap_Get( Me.SizeOfAllProperties) & MKL$(SizeOf(Me)) )
endif
'...
Now this property is known and also the size of it in the second array with same index as the name in the first array.
- It allows to use indexes for known properties
- we know what is a property and what is still a regular udt.
And we know its size that's at least 4 bytes . these 4 bytes (in lDistance) will hold the distance (equal to udt_element_offset) of the property to its owner
Means if VariableXY gerts a property attached the distance of the propery to the variable is SizeOf(VariableXY)
If the new proeprty has a size of 10 bytes and variableXY gets another property attached, the second property will be at a distance= SizeOf(VariableXY) + 10
The distance is virtual and means actually if the structure of variableXY were to print out then the 2 new properties are exactly defined where they have to appear
the distance (is a long wth 4 bytes) also makes sure that a distance can never be 0 because a property consists of these 4 bytes at least.
Only the prototype structure of the properties is able to tell what kind of properties are to find attached to what variables but it has no records where the property is stored
nor what it contains. the variables that get properties attched are mandatory udts that are not attached as property themselves anywhere when properies get attached.
every property that is attached to something is represented by a property-handle that has the size of a quad and is composed from the index of the propertyname and the
pointer to the property-data.
any udt that wants to be able to have properties needs 2 specific subelements : one subelement named "Properties" that must be either of type string or dword and according to that type the properties-handles are stored to a quad-array directly into the properties-string or the array is stored to heap thats pointer wil be placed into the Dword-properties. the second element an udt requires is to save a long variable to hold its owner-index so there is no need to scan. To obtain property information has alway to happen byref. So even the variable is know under its varptr it passes the index - the prototype willl compare if the record of owner(index) equals the varptr of who ever
called the function. the second index to the properties by owner is equal to the order the udt has stored the handles.
We might add a flag to the properties listed in the proplistbyOwner and if the owner declared it is private then the prototype will exit function without result.
It looks quite confussng and as if there would be a lot of array-scanning but no: through the index you know exactly where to obtain name or size of property,
I only have no idea how - if there's something else between private and public
Bookmarks