Possible for Procedure to return LIST?

Just starting out? Need help? Post your questions and find answers here.
thanhmy

Possible for Procedure to return LIST?

Post by thanhmy »

I know it is possible to pass a LIST as parameter to a procedure.
But it is possible for a procedure to return a LIST?
How?
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Possible for Procedure to return LIST?

Post by Bisonte »

if you pass a List to the procedure through a parameter, you don't need to return it.
If you create a list inside a procedure, the only way is via memory.

Code: Select all

Structure s_mylist
  List MyList.s()
EndStructure

Procedure.i CreateList()
  
  Protected *p.s_myList = AllocateStructure(s_mylist)
  
  If Not *p : ProcedureReturn #Null : EndIf
  
  AddElement(*p\MyList())
  *p\MyList() = "Hello"
  AddElement(*p\MyList())
  *p\MyList() = "World"
  
  ProcedureReturn *p
  
EndProcedure

Define *p.s_mylist

*p = CreateList()

If *p
  ForEach *p\MyList()
    Debug *p\MyList()
  Next
EndIf
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Possible for Procedure to return LIST?

Post by Kwai chang caine »

Cool thanks BISONTE 8)
ImageThe happiness is a road...
Not a destination
Post Reply