- Overview
- Syntax
- Declaring a dynamic object
- Instantiating a dynamic object
- Freeing a dynamic object
- Remarks
Dynamic instantiation of object
An object can be dynamically associated with a class, we talk of dynamic instantiation of object. The dynamic instantiation of an object allows you to create an object at a given time and to free this object when it is no longer used. To instantiate an object, you must: - Declare a dynamic object.
- Instantiate the object.
Remarks: - The object is automatically freed when it is no longer used. However, you can force the object destruction (to trigger the destructor execution for example).
- The implementation of polymorphism requires the dynamic instantiation.
- To retrieve the instance of the current object in the methods of the class, use the object keyword (or the this keyword).
MFile is Class Name is string Extension is string Directory is string END
SourceFile is object MFile dynamic // ... // Create the object SourceFile = new MFile // Process on the object... // ... // Free the object delete
Declaring a dynamic object
<ObjectName> is dynamic [object] <ClassName>
Details of syntax
<ObjectName>
Name that identifies the instance of the class. <ClassName>
Name that identifies the class, defined when creating the class in the code editor. Instantiating a dynamic object
<ObjectName> = new <ClassName> ([<Parameters>])
Details of syntax
<ObjectName>
Name that identifies the instance of the class. <ClassName>
Name that identifies the class, defined when creating the class in the code editor. <Parameters>
Optional parameters of constructor. Freeing a dynamic object Syntax 1: Details of syntax
<ObjectName>
Name that identifies the instance of the class.
Syntax 2: Details of syntax
<ObjectName>
Name identifying the instance of the class. This parameter can correspond to a non-dynamic object. Remarks - The object is automatically freed when it is no longer used. However, you can force the object destruction (to trigger the destructor execution for example).
- To check whether a dynamic object is allocated and whether it was not freed yet, this object must be compared to NULL. For example:
IF <Object Name> = NULL ...
IF <Object Name> <> NULL...
This page is also available for…
|
|
|
|