The GetListPtr() function retrieves a pointer to the data fields of current object within a linked list.
FACTS:
* GetListPtr returns a NULL if the lists current item is invalid (End of the list) or empty.
* GetListPtr also works on typed variables
* Don't know what a linked list is ?, make sure you read the LinkedLists tutorial then.
Mini Tutorial #1:
This example creates a list of three people, then simply displays the list size using the GetListPtr function.
; Declare the "Person" user defined type. Type Person ; These Fields will hold this persons name FirstName$ SurName$ EndType ; Dimension the Friends variable of type Person, ; with linked list support Dim Friends As Person List ; Add a person (Billy) to Friends list Friends= New Person Friends.FirstName$ ="Billy" Friends.Surname$ ="Citizen" ; Add another person (Sally) to Friends list Friends= New Person Friends.FirstName$ ="Sally" Friends.Surname$ ="Stevens" ; Add another person (Sally) to Friends list Friends= New Person Friends.FirstName$ ="Olivia" Friends.Surname$ ="Dude" ; Display this persons current position. For Each Friends() ; Get the Pointer of the current type in the list ; and pass it to the ShowPerson function ShowPerson(GetListPtr(Friends())) Next ; display the screen and wait for a key press Sync WaitKey Function ShowPerson(Me As Person Pointer) Print Me.FirstName$+" "+Me.Surname$ EndFunction |
This example would output. Olivia Dude Sally Stevens Billy Citizen |
Mini Tutorial #2:
This example creates a list of three people, then simply displays the list size using the GetListPtr function.
; Create a type called tObject to hold ; our obejcts properties Type tObject x#,y#,z# ; position of this porject EndType ; define the player variable as tobject Dim Player As tObject ; init the player variable Player= New tObject ; Set the players position Player.x#=111.456 Player.Y#=222.456 Player.Z#=333.456 ; show the players position ShowPosition(Player()) ; Delcare a float pointer Dim Ptr As Float Pointer ; Get a pointer to data inside Player ; Ptr is now pointing at the first byte ; of the player type. This will be the ; X field in this example Ptr =GetListPtr(Player()) ; Change the X field *Ptr = 55.55 ; Bump the pointer to the next field (Y) Ptr=Ptr+1 ; Change the Y field *Ptr = 66.66 ; Bump the pointer to the next field (Z) Ptr=Ptr+1 ; Change the Z field *Ptr = 77.77 ; SHow the player again. So we can see the changes ShowPosition(Player()) ; display the screen and wait for a key press Sync WaitKey Function ShowPosition(Me.tobject) Print "Players Position" Print "X:"+Str$(Me.x#) Print "Y:"+Str$(Me.y#) Print "Z:"+Str$(Me.z#) Print "" EndFunction |
This example would output. Players Position X:111.456 Y:222.456 Z:333.456 Players Position X:55.55 Y:66.66 Z:77.77 |
|