Disposing of COM objects
A C/AL variable of the Automation type is only a reference to a COM object that is created and disposed in runtime. Object instances are created with the CREATE
function, and destroyed by the Garbage Collector when the variable leaves the scope. Sometimes it is necessary to destroy an object instance explicitly or ensure that the instance does not exist before calling the CREATE
function on the variable. C/AL functions disposing of automation objects will be described in the current recipe.
How to do it...
A new page will be required for the following example. Create a blank page in C/SIDE. This is only a container for action buttons, so choose to create a blank page without any source table or wizard.
Open the page actions designer and insert two action buttons:
GetProcessorSpeed
andGetMemorySize
.Open the C/AL code designer and access the list of global variables. Declare an
Automation
variable:Name
DataType
Subtype
ShellControl
Automation
Microsoft Shell...