Passing a Link List (NewList) as a parameter to a function

Just starting out? Need help? Post your questions and find answers here.
Master Games
User
User
Posts: 22
Joined: Mon Oct 06, 2003 1:42 am

Passing a Link List (NewList) as a parameter to a function

Post by Master Games »

We would like to know how to past a link list created using NewList command as a parameter in a procedure call. Also we would like to know how to modify the link list inside the procedure call.

example:

Code: Select all

Structure mystruct
  data1.l
  data2.l
EndStructure

NewList mylist.mystruct()

Procedure myproc(*listptr)
  AddElement(listptr())
  listptr()\data1 = 25
  listptr()\data2 = 30
EndProcedure
somewhere in the program we call myproc procedure passing the link list

Code: Select all

  
myproc(@mylist)
Executing this give us this error:

listptr() is not a function, an array, or a linked list
Last edited by Master Games on Sat Jan 03, 2004 10:14 am, edited 1 time in total.
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

I don't know if is what you want to do :

Code: Select all

Structure mystruct 
data1.l 
data2.l 
EndStructure 

NewList mylist.mystruct()  

Procedure myproc() 
AddElement(mylist()) 
mylist()\data1 = 25 
mylist()\data2 = 30 
EndProcedure 

myproc()
Debug mylist()\data1 
Debug mylist()\data2 
Please correct my english
http://purebasic.developpez.com/
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Not possible to add an Element using a pointer.
This is possible:

Code: Select all

Structure MyStruct
  NumericID.l
EndStructure

NewList Original.MyStruct()
NewList TheCopy.MyStruct()
AddElement(Original())
AddElement(TheCopy())

Original()\NumericID = 10

Procedure CopyListItem(*Source.MyStruct, *Destination.MyStruct)
  *Destination\NumericID = *Source\NumericID
EndProcedure

CopyListItem(@Original(), @TheCopy())

Debug TheCopy()\NumericID
Post Reply