Registering Delphi functions

<< Click to Display Table of Contents >>

Navigation:  Using Delphi classes and functions >

Registering Delphi functions

Functions can be registered for global usage (in any script) or for Scripter instance.

To register global function use HtScriptGlobal instance for registration.

 

To register common Delphi function pass function declaration and pointer to function:

 

Example:

 

HtScriptGlobal.RegisterFunc('WeekOf(AValue: TDateTime): Word', @WeekOf);

 

Important note: functions should use "Register" calling convention.

 

Registering class function (non-static):

 

HtScriptGlobal.RegisterFunc('Error(Msg: string; Data: integer)', @TList.Error, nil, TList);

 

Registering object function (method):

 

MyScript.RegisterFunc('Sample()', @MyObject.Sample, MyObject);

 

 

Object function call looks in script code like normal function call:

 

 Sample();

 

but it will execute TMyObject.Sample() method of MyObject object instance.

 

Parameters default values

 

functions can have parameters with default values.

Example:

 

 HtScriptGlobal.RegisterFunc('MyFunc(s: string; Index: integer = 1)', @MyFunc);