Last reviewed: 3/23/2024 8:15:25 AM
Delphi VCL and FireMonkey Applications
Develop Object Pascal applications that manage grammars using your favorite version of Delphi.
The following sections describe the steps for integrating GrammarKit with Delphi VCL and FireMonkey applications.
GrammarKit Unit
GrammarKit includes an Object Pascal source file Chant.GrammarKit.pas comprised of the Object Pascal classes that manage grammars. It also includes an Object Pascal source file Chant.Shared.pas comprised of common Object Pascal classes that all Chant libraries use.
To access the GrammarKit Object Pascal classes within your application, first add a project reference to the GrammarKit Object Pascal source files:
- Within your Delphi project, select Project Options.
- Select the Delphi compiler options.
- Add Search path reference to the GrammarKit unit source file directory: C:\Program Files\Chant\GrammarKit 10\Delphi\source.
- Add unit output path reference to the local directory with a period '.' character.
To access the GrammarKit Object Pascal classes within your application, add a reference to the Chant.Shared and Chant.GrammarKit units in your uses clause.
unit Unit1;
interface
uses
..., Chant.Shared, Chant.GrammarKit;
Add an event handler declaration and Object instance variable to the application declarations.
type
TForm1 = class(TForm)
...
procedure CompileDone(Sender: TObject; Args: TCompileEventArgs);
procedure CompileError(Sender: TObject; Args: TCompileEventArgs);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
_GrammarKit: TGrammarKit;
_Recognizer: TSAPI5Recognizer;
Object Instantiation
Instantiate an instance, set the credentials, and set the event handler message.
// Instantiate GrammarKit object
_GrammarKit := TGrammarKit.Create();
if (_GrammarKit <> nil) then
begin
// Set credentials
_GrammarKit.SetCredentials('Credentials');
// Create recognizer
_Recognizer := _GrammarKit.CreateSAPI5Recognizer();
if (_Recognizer <> nil) then
begin
// Register Event Handlers
_Recognizer.CompileDone := CompileDone;
_Recognizer.CompileError := CompileError;
end;
end;
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 5 | TSAPI5Recognizer | CGrammarKit.SAPI5.dll or CGrammarKitX64.SAPI5.dll |
Microsoft Speech Platform | TMSPRecognizer | CGrammarKit.MSP.dll or CGrammarKitX64.MSP.dll |
Microsoft WindowsMedia | TWindowsMediaRecognizer | CGrammarKit.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.
procedure TForm1.CompileDone(Sender: TObject; Args: TCompileEventArgs);
begin
...
end;
procedure TForm1.CompileError(Sender: TObject; Args: TCompileEventArgs);
var
strErrorMsg: string;
begin
strErrorMsg := '';
strErrorMsg := '(' + IntToStr(Args.Error) + ') ';
strErrorMsg := strErrorMsg + 'error ' + IntToStr(Args.LineNumber) + ' ' + Args.Description + #13 + #10;
...
end;
Development and Deployment Checklist
When developing and deploying Delphi 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 Delphi 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.
- Develop and deploy Delphi 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
Delphi VCL and FireMonkey sample projects are installed at the following location:
- Documents\Chant\GrammarKit 10\Delphi.