Skip to main content

clone

Short summary

This method is used to create a new instance of the object which has the same internal state as the object. If the object is a container class, the references to the content objects are not cloned for this there is the method ICloneable.deepClone.

If an object does not support cloning the return value is CNM_ReturnTypes.CloneResult.CLONE_IS_NOT_SUPPORTED.

If there is not enough memory or the cloning fails because the attribute enable dynamic creation was forgotten the return value is CNM_ReturnTypes.CloneResult.FAILED.

Only if the return value is CNM_ReturnTypes.CloneResult.SUCCESS the output clonedObject points to the new object otherwise clonedObject is NULL.

Attention: For derivations: If a derived class needs clone this method must be overwritten. and don't forget the attribute {attribute 'enable_dynamic_creation'}

Return: CNM_ReturnTypes.CloneResult.SUCCESS: new object clone was created, CNM_ReturnTypes.CloneResult.FAILED: object clone failed CNM_ReturnTypes.CloneResult.CLONE_IS_NOT_SUPPORTED: object does not support cloning

Parameters

NameTypeCommentKind
clonedObjectCNM_AbstractObject.IObjectnew object instance or NULL if somthing went wrongoutput

Code

Declaration

METHOD clone :CNM_ReturnTypes.CloneResult
VAR_OUTPUT
(* new object instance or NULL if somthing went wrong *)
clonedObject :CNM_AbstractObject.IObject;
END_VAR

Implementation

IF (
Tc2_System.F_CheckMemoryArea(pData := THIS, nSize := SIZEOF(THIS^))
= Tc2_System.E_TcMemoryArea.Static
) THEN
clonedObject := THIS^;
clone := CNM_ReturnTypes.CloneResult.SUCCESS;
ELSE
clonedObject := 0;
clone := CNM_ReturnTypes.CloneResult.CLONE_IS_NOT_SUPPORTED;
END_IF