ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / OOP (Object Oriented Programming)
  • Overview
  • Syntax
  • Declaring a dynamic object
  • Instantiating a dynamic object
  • Freeing a dynamic object
  • Remarks
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
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:
  1. Declare a dynamic object.
  2. 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
Syntax

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:
delete <ObjectName>
Details of syntax
<ObjectName>
Name that identifies the instance of the class.

Syntax 2:
<ObjectName> = Null
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...
AndroidJava Special case in Java/Android
The concept of destructor does not exist in Java/Android. Therefore, the code found in the destructor of a class will never be run.
An object is freed by the garbage collector when it is no longer referenced in the application. There is no way to foresee the moment when this operation occurs.
To force an object to be freed, you have the ability to assign it to NULL or to use the Free statement.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help