Add-in Express™ for Microsoft® Office and Delphi® VCLAdd-in Express Home > Add-in Express for Office and VCL > Online Guide > Writing smart tags
Developing Office smart tags
This sample project implementing a smart tag is included in Add-in Express for Office and VCL sample projects
available on the Downloads page. You can find many other examples in
the HowTo section.
Step 1. Creating a new smart tag library project
In the Delphi IDE, close all opened projects, select the File | New | Others menu item, and run the
Add-in Express Smart Tag Library wizard by clicking on the Add-in Express Smart Tag template in the New Item dialog box.

When you select the template and click OK, the Smart Tag project wizard starts. In the wizard windows, you choose the project options.
The project wizard creates and opens the Smart Tag project in the Delphi IDE.

The smart tag project includes the following items:
- The project source files (MySmartTag1.*);
- The type library files (MySmartTag1.ridl and MySmartTag1_TLB.pas);
- The smart tag module (MySmartTag1_IMPL.pas and MySmartTag1_IMPL.dfm) discussed in the following step.
Step 2. Smart Tag module
The smart tag module (MySmartTag1_IMPL.pas and MySmartTag1_IMPL.dfm) is the core part of the smart tag project. The smart
tag module is a container for TadxSmartTag components. The code for MySmartTag1_IMPL.pas is as follows:
unit MySmartTag1_IMPL;
interface
uses
SysUtils, ComObj, ComServ, ActiveX, Variants, adxSmartTag, adxSmartTagTLB, MySmartTag1_TLB;
type
TcoMySmartTag1Recognizer = class(TadxRecognizerObject, IcoMySmartTag1Recognizer)
protected
end;
TcoMySmartTag1Action = class(TadxActionObject, IcoMySmartTag1Action)
protected
end;
TSmartTagModule = class(TadxSmartTagModule)
private
protected
public
end;
implementation
{$R *.dfm}
initialization
TadxRecognizerFactory.Create(ComServer, TcoMySmartTag1Recognizer,
CLASS_coMySmartTag1Recognizer, TSmartTagModule);
TadxActionFactory.Create(ComServer, TcoMySmartTag1Action,
CLASS_coMySmartTag1Action, TSmartTagModule);
end.
The smart tag module contains three classes:
- The "interfaced" classes (TcoMySmartTag1Recognizer and TMySmartTag1Action)
- The smart tag module class (TSmartTagModule).
The "interfaced" classes are descendants of the TadxRecognizerObject class and the TadxActionObject class that implement
the smart tag specific interfaces required by the smart tag architecture: ISmartTagRecognizer, ISmartTagRecognizer2,
ISmartTagAction and ISmartTagAction2. Usually, you don't need to change anything in these classes.
In the smart tag module class, we write the functionality to be implemented by the smart tag. The smart tag module is an
analogue of the Data Module, but unlike the Data Module, the smart tag module allows you to set all properties of your smart tags.
This is exactly what we are going to do now.
Step 3. Smart Tag designer
In the Project Manager window, select the smart tag module, activate the Object Inspector window, specify your smart tag name
in the SmartTagName property (this name appears in the Smart Tags tab on the host application AutoCorrect Options dialog box),
and enter the description of the smart tag through the SmartTagDesc property. These properties depend on Office localization.

The designer of Smart Tag Module allows setting smart tag library properties and adding TadxSmartTag components to the module.
Step 4. Adding a new smart tag
To add a new Smart Tag to your library, select the Add-in Express tab on the Tool Palette, find the TadxSmartTag component
and drag-n-drop it onto the Smart Tag module.

In the Object Inspector window, specify the caption for the added smart tag. The value of the Caption property
will become a caption of the smart tag context menu. Also, specify the phrase(s) recognizable by the smart tag
in the RecognizedWords string collection.

Say, in this sample Smart Tag, the words are as follows:

Step 5. Adding and handling Smart Tag actions
To add a new smart tag action, right-click the smart tag component, select the Smart Tag Actions item on the pop-up menu,
and, in the Editing window, click the Add New button. In the Editing window, select the action, activate the Object Inspector window,
and fill in the Caption property. It depends on Locale. The value of the Caption property is shown as an item of the smart tag
context menu (pop-up).

To handle the click event of this menu item, select the Events tab of the Object Inspector, double click the OnClick event,
and enter your code:
procedure TSmartTagModule.adxSmartTag1Actions0Click(Sender: TObject;
const AppName: WideString; const Target: IDispatch; const Text,
Xml: WideString; LocaleID: Integer);
begin
ShowMessage('Recognized text is ' + Text);
end;
Step 6. Running your smart tag
Choose Register ActiveX Server in menu Run, restart Word or Excel, enter the words recognizable by your smart tag
into a document, and see if the smart tag works.
- In Office 2003 - 2003, choose the Tools | AutoCorrect menu item and find your smart tag on the Smart Tags tab.
- In Office 2007, the path to this dialog is as follows: Office button | Word Options | Add-ins | Manage Smart Tags | Go.
In Office 2010, see File tab | Options | Add-ins | "Manage" Actions | Go.

Step 7. Debugging the smart tag
To debug your Smart Tag, just indicate the add-in host application as the Start Program in the Project Options window.

Step 8. Deploying the smart tag
Make sure your setup project registers the smart tag DLL. Say, in Inno Setup projects you use the 'regserver' command.
Back to Add-in Express for Office and VCL homepage |