RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
C++DelphiTech Partner

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

  • Supports Windows 32 & Windows 64
  • Available for Delphi & C++ Builder 6-10.4  VCL

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: 

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)

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

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.

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:

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:

For this, you should implement your function like this:

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!


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Learn More About Upgrading

About author

Software Developer | B.Tech-CSE at AUT | Delphi/C++ Builder Enthusiast | Microsoft Learn Student Ambassador | Microsoft Azure Certified | Udacity Alumni
Related posts
C++CodeDelphi

Easy Steps To Connect To A MS Access Database With FireDAC In This Windows Sample App

C++DelphiTech Partner

Flexible Brotli Compression Library For Your Windows Delphi/C++ Builder VCL And FMX Apps

DelphiRAD StudioTech Partner

Quickly Work With A COMPort On Linux With Delphi Using A WINSOFT library

C++CodeDelphi

Learn To Build A Python GUI For Solving Complex Tasks With Powerful OpenCV Library In A Delphi Windows App

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES