How to list the list in the structure knowing only the address

Just starting out? Need help? Post your questions and find answers here.
Webarion
New User
New User
Posts: 6
Joined: Tue Sep 14, 2021 8:50 pm

How to list the list in the structure knowing only the address

Post by Webarion »

Hey! Tell me how to work with a list inside the structure, having only an address?

Code: Select all

Structure Struct
  Title.s
  List Childs.Struct()
EndStructure

Global num = 0

Global NewList Virtual.Struct()

Global NewMap Boxes()

Procedure _Add(List lList.Struct())
  *ptr = AddElement(lList())
  lList()\Title = "V" + Str(num)
  num = num + 1
  ProcedureReturn *ptr
EndProcedure


_Add(Virtual())
_Add(Virtual()\Childs())
_Add(Virtual()\Childs())
*element = _Add(Virtual()\Childs()\Childs())


SelectElement(Virtual(), 0)
Debug "1>" + Virtual()\Title

ChangeCurrentElement(Virtual(), *element )
Debug "2>" + Virtual()\Title ; Ok!

; Need to add to *element
AddElement(Virtual()) ; Must be in Virtual()\Childs()\Childs()
Virtual()\Title = "V333" ; NOT OK!

; Need to go through the address *element
ForEach Virtual()
  Debug Virtual()\Title ; NOT OK!
Next
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: How to list the list in the structure knowing only the address

Post by Mijikai »

Hope this helps:

Code: Select all

EnableExplicit

Structure DUMMY
  nfo.s
  List tst.DUMMY()
EndStructure

Global NewList tst.DUMMY()
Global *tst.DUMMY

AddElement(tst())

AddElement(tst()\tst())
tst()\tst()\nfo = "Hello World!"

*tst = @tst()

AddElement(*tst\tst())
*tst\tst()\nfo = "123"

ForEach *tst\tst()
  Debug *tst\tst()\nfo
Next

End
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: How to list the list in the structure knowing only the address

Post by STARGÅTE »

ChangeCurrentElement(Virtual(), *element ) can only change the direct elements in the list, not the nested ones.
But you can use *element with a structure:

Code: Select all

Structure Struct
  Title.s
  List Childs.Struct()
EndStructure

Global num = 0

Global NewList Virtual.Struct()

Global NewMap Boxes()

Procedure _Add(List lList.Struct())
  *ptr = AddElement(lList())
  lList()\Title = "V" + Str(num)
  num = num + 1
  ProcedureReturn *ptr
EndProcedure


_Add(Virtual())
_Add(Virtual()\Childs())
_Add(Virtual()\Childs())
Define *element.Struct = _Add(Virtual()\Childs()\Childs())


SelectElement(Virtual(), 0)
Debug "1>" + Virtual()\Title

Debug "2>" + *element\Title ; Ok!

; Need to add to *element
AddElement(*element\Childs()) ; Must be in Virtual()\Childs()\Childs()
*element\Childs()\Title = "V333" ; NOT OK!

; Need to go through the address *element
ForEach *element\Childs()
  Debug *element\Childs()\Title ; NOT OK!
Next
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Webarion
New User
New User
Posts: 6
Joined: Tue Sep 14, 2021 8:50 pm

Re: How to list the list in the structure knowing only the address

Post by Webarion »

Thanks! You helped me a lot!
Post Reply