ReneMiner
27-02-2013, 16:11
Currently I'm creating some Listbox-alike control that does not use UI (Windows-Drawing) but 2d-drawing in TBGL. Since I want to use the code to handle that control multiple times I need some pointer to the string-array that's assigned to the control. But I've read that strings and their pointers behave different and I don't get the informations puzzled right together. :cray:
Maybe anyone can help?
So this is my example-code:
Type t_Control
'...
RelatedStringArray as Long ' or Else ?
'...
End Type
Dim A() as string
Dim B() as string
Dim C(2) as t_Control
'...
' fill array A() with maybe 20 elements
'...
' -- and I want to assign array A() to Control C(1)
C(1). RelatedStringArray = StrPtr(A)
'...
' fill array B() with maybe 10 elements
'...
C(2). RelatedStringArray = StrPtr(B)
How to tell the control C(any) correctly which array is related to it?
...now I want to call the draw-method for the listbox-control:
Sub Control_Draw(ByVal Index as Long)
Local i, lLast as Long
Local txt as String
' -- now inside this sub I want to get the informations:
' -- which string-array is related to C(Index) ?
' -- so lLast is now supposed to be the following:
' lLast = UBound( -- ? -- C(Index).RelatedStringArray -- ? -- )
'-- is it possible to find out lLast if not storing it to the Control C(Index) ?
' so I could in the end like that:
if lLast > 0 then
For i = 1 to lLast
txt = Peek$(STRING, C(Index).RelatedStringArray + 4 * i ) ' ???
' -- can I get the string that's contained in either A(i) or B(i) so I can print it out now ?
If Len(txt) then
' ... DrawText(txt) ...
Endif
Next i
Endif
End Sub
So basically inside the Sub I need the information how to access a certain element of any string-array and retrieve it's content ("String")
and how to find out UBound(of_any_string_array) would be great since it would need to handle an extra-variable to store it in the t_Control-Type else everytime the arrays UBound changes.
Maybe anyone can help?
So this is my example-code:
Type t_Control
'...
RelatedStringArray as Long ' or Else ?
'...
End Type
Dim A() as string
Dim B() as string
Dim C(2) as t_Control
'...
' fill array A() with maybe 20 elements
'...
' -- and I want to assign array A() to Control C(1)
C(1). RelatedStringArray = StrPtr(A)
'...
' fill array B() with maybe 10 elements
'...
C(2). RelatedStringArray = StrPtr(B)
How to tell the control C(any) correctly which array is related to it?
...now I want to call the draw-method for the listbox-control:
Sub Control_Draw(ByVal Index as Long)
Local i, lLast as Long
Local txt as String
' -- now inside this sub I want to get the informations:
' -- which string-array is related to C(Index) ?
' -- so lLast is now supposed to be the following:
' lLast = UBound( -- ? -- C(Index).RelatedStringArray -- ? -- )
'-- is it possible to find out lLast if not storing it to the Control C(Index) ?
' so I could in the end like that:
if lLast > 0 then
For i = 1 to lLast
txt = Peek$(STRING, C(Index).RelatedStringArray + 4 * i ) ' ???
' -- can I get the string that's contained in either A(i) or B(i) so I can print it out now ?
If Len(txt) then
' ... DrawText(txt) ...
Endif
Next i
Endif
End Sub
So basically inside the Sub I need the information how to access a certain element of any string-array and retrieve it's content ("String")
and how to find out UBound(of_any_string_array) would be great since it would need to handle an extra-variable to store it in the t_Control-Type else everytime the arrays UBound changes.