unit Js;

interface

type

HCkJs = Pointer;
HCkStringBuilder = Pointer;
HCkTask = Pointer;
HCkJsonObject = Pointer;
HCkString = Pointer;


// Note: The callback functions use the cdecl calling convention, while all other functions use stdcall.
TJsAbortCheck = function(): Integer; cdecl;
TJsProgressInfo = procedure(name: PWideChar; value: PWideChar); cdecl;
TJsPercentDone = function(pctDone: Integer): Integer; cdecl;
TJsTaskCompleted = procedure(task: HCkTask); cdecl;


function CkJs_Create: HCkJs;  stdcall;
procedure CkJs_Dispose(handle: HCkJs); stdcall;

procedure CkJs_SetAbortCheck(objHandle: HCkJs; fn: TJsAbortCheck) stdcall;
procedure CkJs_SetProgressInfo(objHandle: HCkJs; fn: TJsProgressInfo) stdcall;
procedure CkJs_SetPercentDone(objHandle: HCkJs; fn: TJsPercentDone) stdcall;
procedure CkJs_SetTaskCompleted(objHandle: HCkJs; fn: TJsTaskCompleted) stdcall;
procedure CkJs_getDebugLogFilePath(objHandle: HCkJs; outPropVal: HCkString);
procedure CkJs_putDebugLogFilePath(objHandle: HCkJs; newPropVal: PWideChar);
function CkJs__debugLogFilePath(objHandle: HCkJs): PWideChar;
procedure CkJs_getLastErrorHtml(objHandle: HCkJs; outPropVal: HCkString);
function CkJs__lastErrorHtml(objHandle: HCkJs): PWideChar;
procedure CkJs_getLastErrorText(objHandle: HCkJs; outPropVal: HCkString);
function CkJs__lastErrorText(objHandle: HCkJs): PWideChar;
procedure CkJs_getLastErrorXml(objHandle: HCkJs; outPropVal: HCkString);
function CkJs__lastErrorXml(objHandle: HCkJs): PWideChar;
function CkJs_getLastMethodSuccess(objHandle: HCkJs): wordbool;
procedure CkJs_putLastMethodSuccess(objHandle: HCkJs; newPropVal: wordbool);
function CkJs_getTimeoutSeconds(objHandle: HCkJs): Integer;
procedure CkJs_putTimeoutSeconds(objHandle: HCkJs; newPropVal: Integer);
function CkJs_getVerboseLogging(objHandle: HCkJs): wordbool;
procedure CkJs_putVerboseLogging(objHandle: HCkJs; newPropVal: wordbool);
procedure CkJs_getVersion(objHandle: HCkJs; outPropVal: HCkString);
function CkJs__version(objHandle: HCkJs): PWideChar;
function CkJs_CallFunction(objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): wordbool;
function CkJs_CallFunctionAsync(objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): HCkTask;
procedure CkJs_ConsoleOutputSb(objHandle: HCkJs; sb: HCkStringBuilder);
function CkJs_Eval(objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): wordbool;
function CkJs_EvalAsync(objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): HCkTask;
function CkJs_SetCkPermission(objHandle: HCkJs; chilkatClassName: PWideChar; permission: PWideChar): wordbool;
implementation

      // Delphi7
{$IF Compilerversion = 15}
      uses Windows, SysUtils, ckDllLoader;
{$ELSE}
      uses Winapi.Windows, System.SysUtils, ckDllLoader;
{$IFEND}

Type
  TCkJs_Create = function : HCkJs; stdcall;
  TCkJs_Dispose = procedure (handle: HCkJs); stdcall;
  TCkJs_SetAbortCheck = procedure (objHandle: HCkJs; fn: TJsAbortCheck); stdcall;
  TCkJs_SetProgressInfo = procedure (objHandle: HCkJs; fn: TJsProgressInfo); stdcall;
  TCkJs_SetPercentDone = procedure (objHandle: HCkJs; fn: TJsPercentDone); stdcall;
  TCkJs_SetTaskCompleted = procedure (objHandle: HCkJs; fn: TJsTaskCompleted); stdcall;
  TCkJs_getDebugLogFilePath = procedure (objHandle: HCkJs; outPropVal: HCkString); stdcall;
  TCkJs_putDebugLogFilePath = procedure (objHandle: HCkJs; newPropVal: PWideChar); stdcall;
  TCkJs__debugLogFilePath = function (objHandle: HCkJs): PWideChar; stdcall;
  TCkJs_getLastErrorHtml = procedure (objHandle: HCkJs; outPropVal: HCkString); stdcall;
  TCkJs__lastErrorHtml = function (objHandle: HCkJs): PWideChar; stdcall;
  TCkJs_getLastErrorText = procedure (objHandle: HCkJs; outPropVal: HCkString); stdcall;
  TCkJs__lastErrorText = function (objHandle: HCkJs): PWideChar; stdcall;
  TCkJs_getLastErrorXml = procedure (objHandle: HCkJs; outPropVal: HCkString); stdcall;
  TCkJs__lastErrorXml = function (objHandle: HCkJs): PWideChar; stdcall;
  TCkJs_getLastMethodSuccess = function (objHandle: HCkJs): wordbool; stdcall;
  TCkJs_putLastMethodSuccess = procedure (objHandle: HCkJs; newPropVal: wordbool); stdcall;
  TCkJs_getTimeoutSeconds = function (objHandle: HCkJs): Integer; stdcall;
  TCkJs_putTimeoutSeconds = procedure (objHandle: HCkJs; newPropVal: Integer); stdcall;
  TCkJs_getVerboseLogging = function (objHandle: HCkJs): wordbool; stdcall;
  TCkJs_putVerboseLogging = procedure (objHandle: HCkJs; newPropVal: wordbool); stdcall;
  TCkJs_getVersion = procedure (objHandle: HCkJs; outPropVal: HCkString); stdcall;
  TCkJs__version = function (objHandle: HCkJs): PWideChar; stdcall;
  TCkJs_CallFunction = function (objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): wordbool; stdcall;
  TCkJs_CallFunctionAsync = function (objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): HCkTask; stdcall;
  TCkJs_ConsoleOutputSb = procedure (objHandle: HCkJs; sb: HCkStringBuilder); stdcall;
  TCkJs_Eval = function (objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): wordbool; stdcall;
  TCkJs_EvalAsync = function (objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): HCkTask; stdcall;
  TCkJs_SetCkPermission = function (objHandle: HCkJs; chilkatClassName: PWideChar; permission: PWideChar): wordbool; stdcall;

var
  _fkt_ptr_arr:   array [0..28] of Pointer;

function _Map( k:Integer; n:String):Pointer;
begin
  Result:=  _fkt_ptr_arr[k];
  if Result = nil then begin
    Chilkat_GetProcedureAddress(Result, n);
    _fkt_ptr_arr[k]:=   Result;
  end;
end;


function CkJs_Create : HCkJs;
begin
  result := TCkJs_Create(_map(0, 'CkJs_Create'));
end;

procedure CkJs_Dispose (handle: HCkJs);
begin
  TCkJs_Dispose(_map(1, 'CkJs_Dispose'))
    (handle);
end;


procedure CkJs_SetAbortCheck (objHandle: HCkJs; fn: TJsAbortCheck);
begin
    TCkJs_SetAbortCheck(_map(2, 'CkJs_SetAbortCheck'))
    (objHandle, fn);
end;
procedure CkJs_SetProgressInfo (objHandle: HCkJs; fn: TJsProgressInfo);
begin
    TCkJs_SetProgressInfo(_map(3, 'CkJs_SetProgressInfo'))
    (objHandle, fn);
end;
procedure CkJs_SetPercentDone (objHandle: HCkJs; fn: TJsPercentDone);
begin
    TCkJs_SetPercentDone(_map(4, 'CkJs_SetPercentDone'))
    (objHandle, fn);
end;
procedure CkJs_SetTaskCompleted (objHandle: HCkJs; fn: TJsTaskCompleted);
begin
    TCkJs_SetTaskCompleted(_map(5, 'CkJs_SetTaskCompleted'))
    (objHandle, fn);
end;

procedure CkJs_getDebugLogFilePath (objHandle: HCkJs; outPropVal: HCkString);
begin
  TCkJs_getDebugLogFilePath(_map(6, 'CkJs_getDebugLogFilePath'))
    (objHandle, outPropVal);
end;

procedure CkJs_putDebugLogFilePath (objHandle: HCkJs; newPropVal: PWideChar);
begin
  TCkJs_putDebugLogFilePath(_map(7, 'CkJs_putDebugLogFilePath'))
    (objHandle, newPropVal);
end;

function CkJs__debugLogFilePath (objHandle: HCkJs): PWideChar;
begin
  result := TCkJs__debugLogFilePath(_map(8, 'CkJs__debugLogFilePath'))
    (objHandle);
end;

procedure CkJs_getLastErrorHtml (objHandle: HCkJs; outPropVal: HCkString);
begin
  TCkJs_getLastErrorHtml(_map(9, 'CkJs_getLastErrorHtml'))
    (objHandle, outPropVal);
end;

function CkJs__lastErrorHtml (objHandle: HCkJs): PWideChar;
begin
  result := TCkJs__lastErrorHtml(_map(10, 'CkJs__lastErrorHtml'))
    (objHandle);
end;

procedure CkJs_getLastErrorText (objHandle: HCkJs; outPropVal: HCkString);
begin
  TCkJs_getLastErrorText(_map(11, 'CkJs_getLastErrorText'))
    (objHandle, outPropVal);
end;

function CkJs__lastErrorText (objHandle: HCkJs): PWideChar;
begin
  result := TCkJs__lastErrorText(_map(12, 'CkJs__lastErrorText'))
    (objHandle);
end;

procedure CkJs_getLastErrorXml (objHandle: HCkJs; outPropVal: HCkString);
begin
  TCkJs_getLastErrorXml(_map(13, 'CkJs_getLastErrorXml'))
    (objHandle, outPropVal);
end;

function CkJs__lastErrorXml (objHandle: HCkJs): PWideChar;
begin
  result := TCkJs__lastErrorXml(_map(14, 'CkJs__lastErrorXml'))
    (objHandle);
end;

function CkJs_getLastMethodSuccess (objHandle: HCkJs): wordbool;
begin
    result := TCkJs_getLastMethodSuccess(_map(15, 'CkJs_getLastMethodSuccess'))
    (objHandle);
end;

procedure CkJs_putLastMethodSuccess (objHandle: HCkJs; newPropVal: wordbool);
begin
  TCkJs_putLastMethodSuccess(_map(16, 'CkJs_putLastMethodSuccess'))
    (objHandle, newPropVal);
end;

function CkJs_getTimeoutSeconds (objHandle: HCkJs): Integer;
begin
    result := TCkJs_getTimeoutSeconds(_map(17, 'CkJs_getTimeoutSeconds'))
    (objHandle);
end;

procedure CkJs_putTimeoutSeconds (objHandle: HCkJs; newPropVal: Integer);
begin
  TCkJs_putTimeoutSeconds(_map(18, 'CkJs_putTimeoutSeconds'))
    (objHandle, newPropVal);
end;

function CkJs_getVerboseLogging (objHandle: HCkJs): wordbool;
begin
    result := TCkJs_getVerboseLogging(_map(19, 'CkJs_getVerboseLogging'))
    (objHandle);
end;

procedure CkJs_putVerboseLogging (objHandle: HCkJs; newPropVal: wordbool);
begin
  TCkJs_putVerboseLogging(_map(20, 'CkJs_putVerboseLogging'))
    (objHandle, newPropVal);
end;

procedure CkJs_getVersion (objHandle: HCkJs; outPropVal: HCkString);
begin
  TCkJs_getVersion(_map(21, 'CkJs_getVersion'))
    (objHandle, outPropVal);
end;

function CkJs__version (objHandle: HCkJs): PWideChar;
begin
  result := TCkJs__version(_map(22, 'CkJs__version'))
    (objHandle);
end;

function CkJs_CallFunction (objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): wordbool;
begin
  result := TCkJs_CallFunction(_map(23, 'CkJs_CallFunction'))
    (objHandle, func, result);
end;

function CkJs_CallFunctionAsync (objHandle: HCkJs; func: HCkJsonObject; result: HCkJsonObject): HCkTask;
begin
  result := TCkJs_CallFunctionAsync(_map(24, 'CkJs_CallFunctionAsync'))
    (objHandle, func, result);
end;

procedure CkJs_ConsoleOutputSb (objHandle: HCkJs; sb: HCkStringBuilder);
begin
  TCkJs_ConsoleOutputSb(_map(25, 'CkJs_ConsoleOutputSb'))
    (objHandle, sb);
end;

function CkJs_Eval (objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): wordbool;
begin
  result := TCkJs_Eval(_map(26, 'CkJs_Eval'))
    (objHandle, jscript, result);
end;

function CkJs_EvalAsync (objHandle: HCkJs; jscript: HCkStringBuilder; result: HCkJsonObject): HCkTask;
begin
  result := TCkJs_EvalAsync(_map(27, 'CkJs_EvalAsync'))
    (objHandle, jscript, result);
end;

function CkJs_SetCkPermission (objHandle: HCkJs; chilkatClassName: PWideChar; permission: PWideChar): wordbool;
begin
  result := TCkJs_SetCkPermission(_map(28, 'CkJs_SetCkPermission'))
    (objHandle, chilkatClassName, permission);
end;

end.
