tag:blogger.com,1999:blog-3701737190756431503.post1098229902213601340..comments2024-01-16T03:43:59.407-05:00Comments on Yanniel's notes: Deep copying (cloning) objects in DelphiUnknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3701737190756431503.post-67487425413234811702015-10-30T13:59:18.499-04:002015-10-30T13:59:18.499-04:00Using Marshall and UnMarshall to copy a TObject de...Using Marshall and UnMarshall to copy a TObject delays processing because it will work with Strings , use sparingly , for example if you using inside a batch processing will delay the total time of this processing.Unknownhttps://www.blogger.com/profile/16177061665906251667noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-4878948350278776152015-09-30T00:42:01.394-04:002015-09-30T00:42:01.394-04:00This method as documented here works well for simp...This method as documented here works well for simple objects, but as you get more complex it starts to break down requiring more and more code to be added to the clone method to register different converters.<br /><br />When I need this type of functionality, I generally will implement a class specific assign method, and then manually copy over the property values that I need in the new object. There are plenty of existing implementations to use as examples in the VCL source. Its a little more work, but doesn't have the extra overhead of marshaling and unmarshaling. SKamradthttps://www.blogger.com/profile/16762334852308664245noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-68447218815706963352015-06-09T08:01:13.631-04:002015-06-09T08:01:13.631-04:00Does this deep copy work with firemonkey applicati...Does this deep copy work with firemonkey application in Android? I need to copy a Bluetooth object (TBluetoothLEDevice)Luiz Roquehttps://www.blogger.com/profile/03360472957635108418noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-3663068998327246422012-02-04T21:19:13.806-05:002012-02-04T21:19:13.806-05:00Uwe, the TObject helper was just for "crazine...Uwe, the TObject helper was just for "craziness". I always wanted TObject to have a Clone method; so I gave it one just for fun. If we talk seriously, then I agree with you about the helper. I like your class function approach. <br /><br />The class function approach could be used to avoid the casting that Wouter was mentioning. The casting can also be avoided by providing the casted class with a regular Clone method that takes no arguments. Something like this:<br /><br />type<br /> TMyObject = class<br /> public<br /> function Clone: TMyObject;<br /> end;<br /><br />Then we can call:<br /><br />MyObject2:= MyObject1.Clone;<br /><br />The whole casting thing happened just because I put the Clone method in TObject. <br /><br />Wouter, I wouldn’t make the Clone method a constructor. I was trying not to construct, since it defeats the purpose of the Clone operation itself.<br /><br />Nonetheless, I like avoiding the casting. The class function approach we just discussed keeps the interface the way you wanted it, but without the use of a constructor.Crisis Fix Adminhttps://www.blogger.com/profile/05146301387107261870noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-40000713784265584102012-02-04T08:31:17.152-05:002012-02-04T08:31:17.152-05:00Hey guys, I thank you for your feedback. I´ll be b...Hey guys, I thank you for your feedback. I´ll be back in a few of hours and I´ll comment further. I am in a rush now ;-)Crisis Fix Adminhttps://www.blogger.com/profile/05146301387107261870noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-26238487310888492262012-02-04T05:18:04.322-05:002012-02-04T05:18:04.322-05:00Just thinking... If clone() would be a constructor...Just thinking... If clone() would be a constructor that takes a prototype (instead of a regular method), you wouldn't need to type-cast the result.<br /><br />MyObject2 := TMyObject.Clone(MyObject1);<br /><br />I'm not sure what obstacles you'd run into while actually implementing it, but such an interface somehow seems more appealing to me.Wouter van Nifterickhttps://www.blogger.com/profile/03516752706481322727noreply@blogger.comtag:blogger.com,1999:blog-3701737190756431503.post-50840150318780943292012-02-04T04:51:05.506-05:002012-02-04T04:51:05.506-05:00The drawback of the TObject helper is, that it wil...The drawback of the TObject helper is, that it will vanish whenever any other helper is insight scope. I would rather suggest a generic approach with a class function like this: <br /><br />class function Clone(Source: T): T;Uwe Raabehttps://www.blogger.com/profile/08727704609084298159noreply@blogger.com