![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Call a JavaScript Function Returning a BooleanSee more JavaScript ExamplesDemonstrates how to call a JavaScript function that returns a boolean.Note: This example requires Chilkat v11.4.0 or greater.
integer li_rc integer li_Success oleobject loo_SbScript oleobject loo_Js oleobject loo_Result oleobject loo_FuncCall integer li_Retval li_Success = 0 // This is the JavaScript function we'll call: // function isEven(number) { // return number % 2 === 0; // } loo_SbScript = create oleobject li_rc = loo_SbScript.ConnectToNewObject("Chilkat.StringBuilder") if li_rc < 0 then destroy loo_SbScript MessageBox("Error","Connecting to COM object failed") return end if loo_SbScript.Append("function isEven(number) { return number % 2 === 0; }") loo_Js = create oleobject li_rc = loo_Js.ConnectToNewObject("Chilkat.Js") loo_Result = create oleobject li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject") loo_Result.EmitCompact = 0 // Call Eval to add the function to the context's global object li_Success = loo_Js.Eval(loo_SbScript,loo_Result) if li_Success = 0 then // Examine the result for an exception. Write-Debug loo_Result.Emit() // Also examine the LastErrorText. Write-Debug loo_Js.LastErrorText destroy loo_SbScript destroy loo_Js destroy loo_Result return end if // ------------------------------------------------------------------------------ // Call the function isEven(8) loo_FuncCall = create oleobject li_rc = loo_FuncCall.ConnectToNewObject("Chilkat.JsonObject") // Create JSON specifying the function name and arguments // { // "name": "isEven", // "args": [ 8 ] // } loo_FuncCall.UpdateString("name","isEven") loo_FuncCall.UpdateInt("args[0]",8) li_Success = loo_Js.CallFunction(loo_FuncCall,loo_Result) if li_Success = 0 then // Examine the result for an exception. Write-Debug loo_Result.Emit() // Also examine the LastErrorText. Write-Debug loo_Js.LastErrorText destroy loo_SbScript destroy loo_Js destroy loo_Result destroy loo_FuncCall return end if Write-Debug loo_Result.Emit() // Output: // { // "type": "bool", // "value": true // } li_Retval = loo_Result.BoolOf("value") Write-Debug string(li_Retval) // Output: // 1 destroy loo_SbScript destroy loo_Js destroy loo_Result destroy loo_FuncCall |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.