Last reviewed: 3/23/2024 8:14:17 AM

C++Builder VCL and FireMonkey Applications

Develop C++ applications that manage grammars using your favorite version of C++Builder.

The following sections describe the steps for integrating GrammarKit with C++Builder VCL and FireMonkey applications.

GrammarKit Header Files

GrammarKit includes C++ header files comprised of the C++Builder classes that manage grammars and automatically load and unload the runtime DLL.

To access the GrammarKit C++Builder classes within your application, first add a project reference to the C++Builder header include files:

  • Within your C++Builder project, select Project Options.
  • Select the C++Builder compiler options.
  • Add Include path reference to the GrammarKit header files directory: C:\Program Files\Chant\GrammarKit 10\CBuilder\include.
  • For 64-bit apps, add Win64 as a conditional to the compiler options.

To access the GrammarKit C++Builder classes within your application, add a reference to the Chant shared and GrammarKit header files in your C++Builder application header file.


#include "Chant.Shared.h"
#include "Chant.GrammarKit.h"

Add a reference in your C++Builder application source file to the Chant shared and GrammarKit code needed to dynamically load and unload the runtime DLL.


#include "Chant.Shared.cpp"
#include "Chant.GrammarKit.cpp"

Object Instantiation

Declare a global variable for the GrammarKit class, instantiate an instance, set the credentials, and set the event handlers.

Add the following to your application header file:


    private:		// User declarations
    CGrammarKit* _GrammarKit;
    CSAPI5Recognizer* _Recognizer;
};
// Event handlers
void CALLBACK CompileDone(void* Sender, CCompileEventArgs* Args);
void CALLBACK CompileError(void* Sender, CCompileEventArgs* Args);

Add the following to your application source file:


 // Instantiate GrammarKit object
_GrammarKit = new CGrammarKit();

if (_GrammarKit =! NULL)
{
    // Set credentials
    _GrammarKit->SetCredentials("Credentials");
    // Create recognizer
    _Recognizer = _GrammarKit->CreateSAPI5Recognizer();
    if (_Recognizer != NULL)
    {
        // Register Event Handlers
        _Recognizer->SetCompileDone(CompileDone);
        _Recognizer->SetCompileError(CompileError);
    }
}

GrammarKit applications require the GrammarKit library (CGrammarKit.dll or CGrammarKitX64.dll) and the applicable GrammarKit Speech API library in the same directory as the application .exe.

Speech API GrammarKit Speech API class GrammarKit Speech API library
Microsoft SAPI 5CSAPI5RecognizerCGrammarKit.SAPI5.dll or CGrammarKitX64.SAPI5.dll
Microsoft Speech PlatformCMSPRecognizerCGrammarKit.MSP.dll or CGrammarKitX64.MSP.dll
Microsoft WindowsMediaCWindowsMediaRecognizerCGrammarKit.WinRT.dll or CGrammarKitX64.WinRT.dll

Event Callbacks

Event callbacks are the mechanism in which the class object sends information back to the application such as compilation is complete or there was an error.


void CALLBACK CompileDone(void* Sender, CCompileEventArgs* Args)
{
    ...
}
void CALLBACK CompileError(void* Sender, CCompileEventArgs* Args)
{
    // Format transcript message
    String strErrorMsg = "(" + IntToStr(Args->GetError()) + ") ";
    strErrorMsg = strErrorMsg + "error " + IntToStr(Args->GetLineNumber()) + " "  + Args->GetDescription() + "\r\n";
    ...
}

Development and Deployment Checklist

When developing and deploying C++Builder VCL and FireMonkey applications, ensure you have a valid license, bundle the correct Chant class library, and configure your installation properly on the target system. Review the following checklist before developing and deploying your applications:

  • Develop and deploy C++Builder VCL and FireMonkey applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy CGrammarKit.dll to the target system and place in the same directory with your application.
  • Copy applicable 32-bit GrammarKit Speech API DLL(s) to the target system and place in the same directory with your application.
  • Deploy C++Builder VCL and FireMonkey applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy CGrammarKitX64.dll to the target system and place in the same directory with your application.
  • Copy applicable 64-bit GrammarKit Speech API DLL(s) to the target system and place in the same directory with your application.

Sample Projects

C++Builder VCL and FireMonkey sample projects are installed at the following location:

  • Documents\Chant\GrammarKit 10\CBuilder.