<< 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.
HtScriptGlobal.RegisterFunc('Error(Msg: string; Data: integer)', @TList.Error, nil, TList);
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.
functions can have parameters with default values.
Example:
HtScriptGlobal.RegisterFunc('MyFunc(s: string; Index: integer = 1)', @MyFunc);