Page 1 of 1

[Implemented] inkedList copy element ability!

Posted: Sat Dec 22, 2001 1:09 am
by BackupUser
Restored from previous forum. Originally posted by Shagwana.

Right first off let me put some code up;

Code: Select all

;A structure to hold info
Structure ListInfo
   Name.s 
   EndStructure
  
  
;Fill the list  
NewList Pep.ListInfo()

AddElement(Pep()) 
Pep()\Name$="1:Shagwana"  

AddElement(Pep()) 
Pep()\Name$="2:Robins"

AddElement(Pep()) 
Pep()\Name$="3:Blu_Matt"

AddElement(Pep()) 
Pep()\Name$="4:Gfk"

AddElement(Pep()) 
Pep()\Name$="5:xMystik"
        


Procedure DisplayPep()
  ResetList(Pep())
  m$="List size "+Str(CountList(Pep()))+";"+Chr(10)+Chr(10)
  While NextElement(Pep())       
    m$=m$+Pep()\Name$+Chr(10)
    Wend
  MessageRequester("Pep list:", m$, 0)
  EndProcedure

Global Buffer.ListInfo ;used in copy

;Show the list
DisplayPep()

;Move the last element to the front of the list
LastElement(Pep())

;Buffer.ListInfo=Pep()   ;WISHLIST
Buffer.ListInfo\Name$=Pep()\Name$

DeleteElement(Pep())
FirstElement(Pep())
InsertElement(Pep())

;Pep()=Buffer.ListInfo    ;WISHLIST
Pep()\Name$=Buffer.ListInfo\Name$

;Reshow the list - last should be first!
DisplayPep()
End

What I would like to see is the ability to do 'Buffer.ListInfo=Pep()' and 'Pep()=Buffer.ListInfo' in the above code. As it stands, when we need to duplicate the data held in a list, we have to iterate throught each field in the element and copy it over - not good for big structures .

http://www.sublimegames.com

Posted: Sat Dec 22, 2001 1:24 am
by BackupUser
Restored from previous forum. Originally posted by Shagwana.

Purembasic is great, i just gota say - if anyone is intrested in a workaround, then;

CopyMemory(*Pep(), @Buffer, SizeOf(ListInfo))

to copy the Pep() element to the Buffer, then;

CopyMemory( @Buffer, *Pep(), SizeOf(ListInfo))

To copy the Buffer values to the Pep() element



http://www.sublimegames.com

Posted: Sat Dec 22, 2001 1:40 am
by BackupUser
Restored from previous forum. Originally posted by Shagwana.

Come to think of it, the above hack might not copy the sting, it might instead copy the pointer to the string - so the data looks ok, but is not! . The above hack should be fine on numerical data!

http://www.sublimegames.com

Posted: Sat Dec 22, 2001 1:45 am
by BackupUser
Restored from previous forum. Originally posted by Shagwana.

So a little bit for playing around and testing;

Code: Select all


;A structure to hold info
Structure Info
   Name.s 
   Value.l
   EndStructure
  
a.Info\Name$="Stephen"
a\Value=40
b.Info\Name$="Angie"
b\Value=100

MessageRequester("a values:", a\Name$+Chr(10)+Str(a\Value), 0)  

b.Info=a.Info    ;Wanted feature!
;CopyMemory(@a, @b, SizeOf(Info)) ;my hack problem :(

a\Value=3
a\Name$="something else"

;Should display "Stephen" and Value '40'
MessageRequester("b values:", b\Name$+Chr(10)+Str(b\Value), 0)  

End

I hope that example shows what i want a bit better!

Edited by - Shagwana on 22 December 2001 01:58:50

Edited by - Shagwana on 22 December 2001 02:01:33