Copy A.MyType to B.MyType

Blitz3D Forums/Blitz3D Programming/Copy A.MyType to B.MyType

Neraj(Posted 2006) [#1]
I couldnt find something for that in the manual, how do i copy an object?
For instance, i want my object A.MyType be the same as B.MyType.
I could think of two methods, but also they seem to work in general, at some points something seems wrong. I wonder wether it is "allowed" what im doing or there is something wrong elsewhere.
1)
A=B.MyType
2)
MyHandle=Handle(B.MyType)
A=Object.MyType(MyHandle)

Thanks for your help.


Damien Sturdy(Posted 2006) [#2]
It's not that simple.

You're making A and B point to the same object. what you need to do is make A and B different objects containing similar information.

You will need to do:
A.mytype=new mytype
A.Field1=B.Field1
A.Field2=B.Field2
A.Field3=B.Field3
A.Field4=B.Field4
A.Field5=B.Field5
A.Field6=B.Field6
A.Field7=B.Field7



Neraj(Posted 2006) [#3]
Ok, i understand why what i was doing isnt working. But i wonder if there is a quicker method than
A.Field1=B.Field1
A.Field2=B.Field2
A.Field3=B.Field3
....
?


Damien Sturdy(Posted 2006) [#4]
Nope, I'm afraid not. I wish there was a "CopyOf" function.

A.Mytype=CopyOf B.Mytype


Unless anyone else knows any cunning methods?


_PJ_(Posted 2006) [#5]
when you say 'quicker method' do you mean quicker to program or quicker on runtime?

if it's the former:



((Hope this helps, Ive not tried it or anything, just wrote it here in browser window!))


octothorpe(Posted 2006) [#6]
C++ provides default copy constructors for "plain old data" (POD) structures. There's no functionality like this in Blitz.

If you're not concerned about performance, you could use Hash Tables, which can be copied programmatically.


Neraj(Posted 2006) [#7]
With "quicker method", i ment easier to programm, especially easier to make changes. I like to change most things a little over time, with this method i would have a lot of work if i, for example, add another integer to the type or whatever.
Of course performance is also an issue.
Well, thanks for your help.