Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

CloneObject

This cool method lets you create an exact (well, almost exact) duplicate of an object. The only difference between the two is the name you assign the new one. The only bad thing we have to say about CloneObject is that it’s available only at design-time—we can think of all kinds of cool things we could do with it at runtime.

Usage

oObject.CloneObject( cNewName )

The newly cloned object becomes a member of the same container the original object is in. That is, if you clone a label on a form, the new label is added to the same form.

All the properties and methods of the original are copied to the clone.

Example

* Assume the Form Designer is open and a single object (that
* sits right on the form) is selected.
= ASELOBJ(aObject)    && Get a reference to the selected object
= ASELOBJ(oContainer, 1)     && Get a reference to the form
aObject[1].CloneObject( "NewOne" )
* Now we can reference it through the container
? oContainer[1].NewOne.Name  && Returns "NewOne"

See Also

AddObject, AddProperty, ASelObj()