It is currently Fri May 25, 2018 9:47 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Problem using CopyStructure
PostPosted: Wed May 16, 2018 6:43 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 833
Location: Canada
This works fine...
Code:
Structure testlist
  name.i
  flag.i
EndStructure

test.testlist
tmp.testlist

tmp\name=21
Debug tmp\name
Debug "----------"

CopyStructure(@tmp,@test.testlist,testlist)

Debug test\name


But can you do the same with Structure and List?

Code:
Structure testlist
  name.i
  flag.i
EndStructure

NewList test.testlist()
NewList tmp.testlist()

AddElement(tmp()):tmp()\name=21
AddElement(tmp()):tmp()\name=42
AddElement(tmp()):tmp()\name=69
AddElement(tmp()):tmp()\name=99

ForEach tmp()
  Debug tmp()\name
Next
Debug "----------"

CopyStructure(@tmp(),@test(),testlist)  ;<--------- This doesn't work, what is the proper syntax?

ForEach test()
  Debug test()\name
Next

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem using CopyStructure
PostPosted: Wed May 16, 2018 7:18 am 
Offline
User
User

Joined: Sat Jun 22, 2013 4:06 pm
Posts: 11
Location: Coutances FRANCE
Code:
Structure testlist
  name.i
  flag.i
EndStructure

NewList test.testlist()
NewList tmp.testlist()

AddElement(tmp()):AddElement(test()):tmp()\name=21
AddElement(tmp()):AddElement(test()):tmp()\name=42
AddElement(tmp()):AddElement(test()):tmp()\name=69
AddElement(tmp()):AddElement(test()):tmp()\name=99

ForEach tmp()
  Debug tmp()\name
Next
Debug "----------"

CopyStructure(@tmp(),@test(),testlist)  ;<--------- This doesn't work, what is the proper syntax?

ForEach test()
  Debug test()\name
Next


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem using CopyStructure
PostPosted: Wed May 16, 2018 8:50 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 377
Location: France
CopyStructure() copies the elements one by one
1. Need to copy each element.
2. Target element must exist.

Code:
Structure testlist
  name.i
  flag.i
EndStructure

NewList test.testlist()
NewList tmp.testlist()

AddElement(tmp()):tmp()\name=21
AddElement(tmp()):tmp()\name=42
AddElement(tmp()):tmp()\name=69
AddElement(tmp()):tmp()\name=99

ForEach tmp()
  Debug tmp()\name
Next
Debug "----------"

; OLD
; CopyStructure(@tmp(),@test(),testlist)  ;<--------- This doesn't work, what is the proper syntax?

; NEW
ForEach tmp()
    AddElement(test())
    CopyStructure(@tmp(), @test(), testlist)
Next

ForEach test()
  Debug test()\name
Next

Tested.
Code:
21
42
69
99
----------
21
42
69
99


PS. Micoute's solution works, but copie only last element.
Work fine like this
Code:
; CopyStructure(@tmp(),@test(),testlist)

ResetList(test())
ForEach tmp()
    NextElement(test())
    CopyStructure(@tmp(),@test(),testlist)
Next

But at end, think simple...
Code:
; CopyStructure(@tmp(),@test(),testlist)  ;<--------- This doesn't work, what is the proper syntax?
CopyList(tmp(), test())

:wink:

_________________
(English is not my native language, I used an online translator)
Windows 10 x64 - CPU intel i3 - RAM 16Go - NVidia GT 620 - 1920x1080 - Linux Slackware, Debian - xfce - (VirtualBox 5) - raspberry pi


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem using CopyStructure
PostPosted: Wed May 16, 2018 10:47 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3856
Location: Germany
When you want to copy lists, why you don't use the right command:
Code:
CopyList()

:?:

Bernd


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem using CopyStructure
PostPosted: Wed May 16, 2018 2:21 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 833
Location: Canada
Marc56us wrote:
But at end, think simple...
Code:
; CopyStructure(@tmp(),@test(),testlist)  ;<--------- This doesn't work, what is the proper syntax?
CopyList(tmp(), test())

:wink:


Dohhh !! :oops:

Was so focused on the structure part, didn't think of the list.
And some speed test show CopyList() is a bit faster than looping through with CopyStructure()

Thanks !

_________________
Image Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye