clone

Can I use assign to duplicate an object of objects?

耗尽温柔 提交于 2019-12-02 01:11:00
I have an object that inherits in 3rd degree from TPersistent and I want to clone it using the Assign procedure. MyFirstObj := GrandSonOfPersistent.Create(); //I modify the objects inside MyFirstObj MySecondObj := GrandSonOfPersistent.Create(); MySecondObj.Assign(MyFirstObject); How can I check it worked? Does it work when the objects have many other objects? I am trying to clone an object, is this the correct way to do it? Assign is a virtual method. Any descendent classes that inherit from TPersistent should override Assign to handle deep copying of any new members added on top of the base

How to deep copy (clone) an object with array members in Javascript?

喜你入骨 提交于 2019-12-02 00:16:50
Introduction I have a Class Persons that contains an array of Person and functions : function Persons() { this.mItems = []; // Array of Objects Person } Persons.prototype = { calculateScores : function() { // Do some stuff } } The Class Person has members and functions : function Person(name) { this.name = name; // Name of the Person this.score = 0; } Person.prototype = { calculateScore : function() { // Do some stuff } } I want that the program does the following things : var persons = new Persons(); var person0 = new Person("John"); var person1 = new Person("Sam"); persons.mItems.push

Copying a 2D array using .clone() still references original data

笑着哭i 提交于 2019-12-01 23:42:05
问题 Okay, I know this question has been asked before: Previous Question I have also looked into a few other threads and websites and they all seem to create more questions than answers. Josh Bloch on Design - an article discussing .clone(); But I still couldn't work out the answer to my problem. When I clone my 2D array: values = Map.mapValues.clone(); I still cannot safely modify the content of values as it still modifies the content of Map.mapValues . Is there actually a way to copy an array

C++ elegantly clone derived class by calling base class

隐身守侯 提交于 2019-12-01 22:49:23
I have a need to clone a derived class given only a reference or pointer to the base class. The following code does the job, but doesn't seem elegant, because I'm putting boilerplate code into many derived classes C, D, E that are siblings of B (not shown) that just calls the default copy constructor of each. Isn't that what the default copy constructor is for, if only it could be virtual? Is there a better way? Making a virtual assignment operator would be wrong, as I don't want C to assign to B, B to D, etc, just clone B, C, D or E. #include <iostream> using namespace std; class A { public:

How to clone two columns in a table using jQuery

流过昼夜 提交于 2019-12-01 17:43:33
I am trying to clone 2 columns from a table to a new table using jQuery. The source table is below: <table id="sourceT"> <tr> <td>Col 1</td> <td>Col 2</td> <td>Col 3</td> </tr> <tr> <td>Col 1 - value</td> <td>Col 2 - value</td> <td>Col 3 - value</td> </tr> </table> <table id="targetT"></table> What I tried is, $("#sourceT").find("tr > td:nth-child(1), tr > td:nth-child(2)").each(function () { $("#targetT").append($("<tr></tr>").append($(this).clone())); }); I only want to copy first and second columns to a new table like <table id="targetT"> <tr> <td>Col 1</td> <td>Col 2</td> </tr> <tr> <td

jQuery.clone() IE problem

泪湿孤枕 提交于 2019-12-01 17:36:05
I'm have some that uses jQuery.clone() to get the html of a page and then add it to a pre tag. It works correctly in Firefox and Chrome, but nothing happens in IE: <!DOCTYPE html> <html> <head> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script> $(function(){ $('button').click(function(){ var $clone = $('html').clone(); $('#output').text($clone.html()); }); }); </script> <style> article, aside,

jQuery.clone() IE problem

送分小仙女□ 提交于 2019-12-01 16:40:27
问题 I'm have some that uses jQuery.clone() to get the html of a page and then add it to a pre tag. It works correctly in Firefox and Chrome, but nothing happens in IE: <!DOCTYPE html> <html> <head> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script> $(function(){ $('button').click(function(){ var

How do I clone a Dictionary object?

橙三吉。 提交于 2019-12-01 15:55:52
I have a Dictionary object in VBScript. How can I copy all the objects contained in it to a new Dictionary , i.e. create a clone/duplicate of the dictionary? Create a new Dictionary object, iterate through the keys in the original dictionary and adds these keys and the corresponding values to the new dictionary, like this: Function CloneDictionary(Dict) Dim newDict Set newDict = CreateObject("Scripting.Dictionary") For Each key in Dict.Keys newDict.Add key, Dict(key) Next newDict.CompareMode = Dict.CompareMode Set CloneDictionary = newDict End Function This should be enough in most cases.

jQuery clone() FireFox bug - can't submit a cloned form

百般思念 提交于 2019-12-01 15:28:11
问题 I want to add/remove dynamically forms. I'm using forms that are stored in a table, each row has form. I have 2 tables: - the one being displayed - the one surrounded by with the temporary row that I want to clone and insert into the displayed table. Everything works fine in IE but the cloned row with its form in Firefox can't be submitted. If i don't clone the row but just insert it, I can submit the form but I need to be able to reuse that row to insert it again so I need to use cloning.

Cloning a bootstrap element with an event listener

拥有回忆 提交于 2019-12-01 15:15:42
I'm trying to clone a bootstrap element that has data-toggle behavior provided by bootstrap: HTML <div class="container"> <button aria-expanded="false" data-target="#collapsible_obj_0" data-toggle="collapse" class="btn btn-link collapsed">click here</button> <div style="height: 0px;" aria-expanded="false" id="collapsible_obj_0" class="collapse"> <span>foo</span> </div> </div> After cloning, I am changing the ID of the div to a new unique id, and the data-target of the button to point to the new div . JS var header = objectContainer.clone(true); var counter = this.collapsibleObjCounter++; var