What I am doing wrong here:? ::)
- I just want an array of pointers pointing to UDTs so I can use "SETTYPE" to make my source more readable.-
DEF FILTERS[10]:POINTER
TYPE _FILTER
DEF Filter01 :INT
DEF Filter02 :INT
DEF Filter03 :INT
ENDTYPE
SETTYPE FILTERS,_FILTER
FILTERS[1] = NEW(_FILTER,1)
#FILTERS[1].Filter01 = 1
#FILTERS[1].Filter02 = 2
#FILTERS[1].Filter03 = 3
PRINT #FILTERS[1].Filter01
PRINT #FILTERS[1].Filter02
PRINT #FILTERS[1].Filter03
WAITCON
Hmm i'm not sure why dont work with array of pointers but this way work:
' pointers ...
'DEF FILTERS[10]:POINTER
TYPE _udtFILTER
DEF Filter01:INT
DEF Filter02:INT
DEF Filter03:INT
ENDTYPE
DEF FILTERS As POINTER
FILTERS = NEW(_udtFILTER,1)
SETTYPE FILTERS,_udtFILTER
#FILTERS.Filter01 = 1
#FILTERS.Filter02 = 2
#FILTERS.Filter03 = 3
PRINT #FILTERS.Filter01
PRINT #FILTERS.Filter02
PRINT #FILTERS.Filter03
WAITCON
Heh i just try to start with null element of array and works :)
' pointers ...
'DEF FILTERS[10]:POINTER
TYPE _udtFILTER
DEF Filter01:INT
DEF Filter02:INT
DEF Filter03:INT
ENDTYPE
DEF FILTERS[10] As POINTER
FILTERS[0] = NEW(_udtFILTER,1)
SETTYPE FILTERS[0],_udtFILTER
#FILTERS[0].Filter01 = 1
#FILTERS[0].Filter02 = 2
#FILTERS[0].Filter03 = 3
PRINT #FILTERS[0].Filter01
PRINT #FILTERS[0].Filter02
PRINT #FILTERS[0].Filter03
WAITCON
I think this could be the solution...
This makes a matrix of 10 UDT's, I think this was the intension?
Good luck!
Johnny
openconsole
DEF FILTERS:POINTER
TYPE _FILTER
DEF Filter01 :INT
DEF Filter02 :INT
DEF Filter03 :INT
ENDTYPE
SETTYPE FILTERS,_FILTER
FILTERS = NEW(_FILTER,10)
#FILTERS[1].Filter01 = 1
#FILTERS[1].Filter02 = 2
#FILTERS[1].Filter03 = 3
PRINT #FILTERS[1].Filter01
PRINT #FILTERS[1].Filter02
PRINT #FILTERS[1].Filter03
WAITCON
DELETE FILTERS
CLOSECONSOLE
I try also next option and work but maby Johnny solution is better. ;)
' pointers ...
'DEF FILTERS[10]:POINTER
TYPE _udtFILTER
DEF Filter01:INT
DEF Filter02:INT
DEF Filter03:INT
DEF Filter04:INT
DEF Filter05:INT
DEF Filter06:INT
ENDTYPE
DEF FILTERS[10] As POINTER
FILTERS[0] = NEW(_udtFILTER,1)
FILTERS[1] = NEW(_udtFILTER,1)
SETTYPE FILTERS[0],_udtFILTER:SETTYPE FILTERS[1],_udtFILTER
#FILTERS[0].Filter01 = 1
#FILTERS[0].Filter02 = 2
#FILTERS[0].Filter03 = 3
PRINT #FILTERS[0].Filter01
PRINT #FILTERS[0].Filter02
PRINT #FILTERS[0].Filter03
#FILTERS[1].Filter04 = 4
#FILTERS[1].Filter05 = 5
#FILTERS[1].Filter06 = 6
PRINT #FILTERS[1].Filter04
PRINT #FILTERS[1].Filter05
PRINT #FILTERS[1].Filter06
WAITCON
This makes a matrix of 10 UDT's, I think this was the intension?
Not quite.
The UDT is huge â€ââ,¬Å" above is just simplified â€ââ,¬Å" and will sit in a dll.
So I want to allocate only that much memory necessary not the entire matrix.
That’s the reason I want a pointer array and only certain elements will have valid pointers to a UDT like
â€Ã...“FILTERS[1] and FILTERS[22]â€Ã, depends what will be requested from the dll.
This works :
DEF FILTERI[10] :INT
DEF FILTERS,pTemp :POINTER
TYPE _FILTER
DEF Filter01 :INT
DEF Filter02 :INT
DEF Filter03 :INT
ENDTYPE
pTemp = NEW(_FILTER,1)
FILTERI[1] = ##<INT>pTemp
FILTERS = ##<POINTER>FILTERI[1]
SETTYPE FILTERS,_FILTER
#FILTERS.Filter01 = 1
#FILTERS.Filter02 = 2
#FILTERS.Filter03 = 3
PRINT #FILTERS.Filter01
PRINT #FILTERS.Filter02
PRINT #FILTERS.Filter03
DELETE FILTERS
WAITCON
but I think could be a more condensed way somehow. ;D
Ah, that's your plan... :)
The point is that your matrix should stay a matrix of pointers, and some will point to NEW-created UDT's, I think that in that case, you need a "holder" for the pointer address that can be type set as the UDT:
openconsole
DEF FILTERS[30],Temp:POINTER
TYPE _FILTER
DEF Filter01 :INT
DEF Filter02 :INT
DEF Filter03 :INT
ENDTYPE
SETTYPE Temp,_FILTER
FILTERS[1] = NEW(_FILTER,1)
FILTERS[22] = NEW(_FILTER,1)
Temp = FILTERS[1]
#Temp.Filter01 = 1
#Temp.Filter02 = 2
#Temp.Filter03 = 3
Temp = FILTERS[22]
#Temp.Filter01 = 4
#Temp.Filter02 = 5
#Temp.Filter03 = 6
Temp = FILTERS[1]
PRINT #Temp.Filter01
PRINT #Temp.Filter02
PRINT #Temp.Filter03
Temp = FILTERS[22]
PRINT #Temp.Filter01
PRINT #Temp.Filter02
PRINT #Temp.Filter03
WAITCON
DELETE FILTERS[1]
DELETE FILTERS[22]
CLOSECONSOLE
Thanks Johnny!
That is exactly I was seeking. ;)
Sometimes I have a notion that some expressions are not jet implemented but the compiler doesn't throw errors just does something undetermined.
I personally think this should work but it does something else: :-\
#FILTERS[1].Filter02 = x
Yes Ficko, indeed, one could expect that your notation would also work fine, but only in case that multiple indirection was supported in that way... :-\
It is possible that this rather complicated combination of a pointer-matrix pointing towards a UDT in a memory was never intended to work this way.
A search in the help file for "Multiple indirection" gave (along others information) this answer:
'To use the EBASIC style dereference use a temporary pointer
temp = #<POINTER>p2
#<INT>temp = 7
It seems my solution was not so crazy at all...
Anyway, the "workaround" is easily done! So no problem! 8)
Johnny