Creating and destroying objects

<< Click to Display Table of Contents >>

Navigation:  Using Delphi classes and functions >

Creating and destroying objects

Objects created in script using constructors, for example

 

L := TStringList.Create();

 

will be destroyed automatically with scripter instance. Also you can destroy it manually via Free() call:

 

L.Free();

 

After calling the destructor, object variable is set to null.

 

If an object created in script should be available after script is destroyed, release it using

 

ReleaseObject(O: TObject): TObject

 

function.

If you create an object in Delphi code (for using in script) and want this object to be added into auto-free list use

 

Scripter.CreateObject(MyObject);

 

method.

 

Also you can set AutoFreeResult flag when registering a function:

 

  HtScriptGlobal.RegisterFunc('CreateSpecialList: TObject', 

   @CreateSpecialList).AutoFreeResult := true;

 

so all objects created via this function will be destroyed automatically.

 

Creating and destroying Components and Controls.

 

Since TComponent has Owner/Components mechanism for destroying, there is special soAutoFreeComponents flag in Script.Options.

When set to false (by default) all objects of TComponent type created by constructor and having Owner will not be destroyed by script.