Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Take your Delphi & C++ Builder projects to the next level with Chakra JScript Engine!

Intro

Many Delphi developers adore the language integration options of the Embarcadero Delphi and C++ Builder. For instance, you can utilize Assembly language within the Delphi code by just opening asm scope. This is an inline assembly feature. Moreover, you can integrate other languages like Java & JavaScript.

With this option, you can create your application 5x faster or even 10x faster with Delphi and C++ Builder. Since this is all about Rapid Application Development (RAD), Delphi & C++ Builder communities love it.

Let’s investigate the JSEngine by WINSOFT which offers to use the Microsoft ChakraCore JavaScript engine with Delphi and C++ Builder. This is a commercial library that has a trial version with all features for evaluation only and if you wish to distribute the JSEngine library as a part of your project you should get a license.

Furthermore, you should know about the Microsoft ChakraCore JS Engine third party notices. Because ChakraCore uses third party projects from different authors.

Notice – Future of ChakraCore

As you may have heard Microsoft Edge no longer uses Chakra. Microsoft will continue to provide security updates for Chakracore 1.11 until 9th March 2021 but do not intend to support it after that. However, ChakraCore is planned to continue as a community project targeted primarily at embedded use cases. A new version plan – Chakracore 1.12

[Microsoft]

Specifications

Configuration

The first step is always installing the new libraries into your development environment. Here is a short tutorial on installing the library correctly.

The second step is opening the demo source code and adding the ChakraCore.dll application extension to your project folder. If you are building your application for Windows 32-bit you must copy the x86 ChakraCore.dll extension. Or it is for Windows 64-bit you need to copy the x64 ChakraCore.dll application extension. You can get the application extension from the Library folder.

Development

The third main step is to add the units to the uses block. The result should be like this: 

[crayon-673f5dc6a7b91098100583/]

So, now we are ready to use the JSEngine in our project! Here is the user interface:

To use ChakraCore and JSEngine we should create three instances for TJsEngine (jsengine.pas) and JsValueRef (ChakraCommon.pas)

[crayon-673f5dc6a7b9a253180835/]

All right, now let’s create Engine object and execute simple expression.

[crayon-673f5dc6a7b9d627741990/]

Now, we should get the JavaScript code from the MemoScriptSimple component and call RunScript function, after that we can convert the result to String with Engine.ConvertToString function. Here is the implementation.

[crayon-673f5dc6a7b9f263039238/]

If you would like to use a native function, you should register it first with an exact name of the function. Then you can run your native function. Here is the implementation:

[crayon-673f5dc6a7ba1810039014/]

If you would like to run your functions it takes little more work, because you need to first run the script itself and you should call the function with needed parameters.

For instance, you want to run this script:

[crayon-673f5dc6a7ba3916164546/]

For this, you should implement your function like this:

[crayon-673f5dc6a7ba4917111628/]

Nice! It all goes like this. Check out the full WINSOFT JSEngine for Delphi and C++ Builder!

Like what you see? You can get the JSEngine Component and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4 today!

Exit mobile version