top of page

Grupo de Interesses Compartilhados

Público·12 membros

How to Use Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo to Run jаvascript in Delphi Applications


How to Use Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo to Run jÐvascript in Delphi Applications




Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo is a library that allows you to use Microsoft ChakraCore jÐvascript engine in your Delphi applications. It supports Windows 32 and Windows 64 platforms and is compatible with Delphi 6 - 10.2 and Lazarus 1.6.4. In this article, we will show you how to install and use Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo to run jÐvascript code in your Delphi projects.




Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo



Installation




To install Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo, you need to download the library from Developer.Team website[^1^]. You will get a zip file containing the source code and the compiled binaries for different Delphi versions. Extract the zip file to a folder of your choice and add the path to the library folder to your Delphi library path.


Usage




To use Winsoft JSEngine 2.7 D6-Delphi 10.2 Tokyo, you need to add the unit WJSEngine to your uses clause. Then, you can create an instance of TWJSEngine class and use its methods and properties to execute jÐvascript code.


For example, you can use the Run method to run a simple jÐvascript expression and get the result as a variant:


uses


WJSEngine;


var


Engine: TWJSEngine;


Result: Variant;


begin


Engine := TWJSEngine.Create;


try


Result := Engine.Run('1 + 1');


ShowMessage(Result); // shows 2


finally


Engine.Free;


end;


end;


You can also use the RunFile method to run a jÐvascript file from disk:


uses


WJSEngine;


var


Engine: TWJSEngine;


begin


Engine := TWJSEngine.Create;


try


Engine.RunFile('C:\test.js'); // runs the jÐvascript code in test.js file


// do something with the engine


finally


Engine.Free;


end;


end;


The TWJSEngine class also provides methods to define and access global variables and functions in jÐvascript context. For example, you can use the SetGlobalVar method to set a global variable in jÐvascript:


uses


WJSEngine;


var


Engine: TWJSEngine;


begin


Engine := TWJSEngine.Create;


try


Engine.SetGlobalVar('name', 'John'); // sets a global variable name with value 'John'


Engine.Run('alert("Hello, " + name + "!")'); // shows an alert message with name variable


// do something with the engine


finally


Engine.Free;


end;


end;


You can also use the GetGlobalVar method to get a global variable from jÐvascript:


uses


WJSEngine;


var


Engine: TWJSEngine;


Result: Variant;


begin


Engine := TWJSEngine.Create;


try


Engine.Run('var age = prompt("Enter your age")'); // prompts for age input and sets a global variable age


Result := Engine.GetGlobalVar('age'); // gets the global variable age as a variant


ShowMessage(Result); // shows the age input


// do something with the engine


finally


Engine.Free; e0e6b7cb5c


Informações

Bem-vindo ao grupo! Você pode se conectar com outros membros...
bottom of page