Developing smart tags for Excel 2007, 2003, 2002,
Word, PowerPoint and Outlook in Delphi
Add-in Express
for Borland VCL
Add-in Express Home > Add-in Express VCL > Online Guide > Writing smart tags
Smart tag libraries
Smart Tags is an element of text in an Office document that is recognized as having custom actions associated with it. This technology was introduced in Office 2002 (XP) and supported in Office 2003 and 2007.
Add-in Express VCL allows you to build a new smart tag for Microsoft Excel, Word, PowerPoint and Outlook (with Word as the default e-mail editor) with a few clicks. Although a smart tag solution based on Add-in Express implements one smart tag recognizer, we call this solution the smart tag library. The point is that Add-in Express architecture makes possible creating several smart tags within one solution and one recognizer. That is why we consider smart tag solutions based on Add-in Express smart tag libraries, rather than one smart tag.
Add-in Express Smart Tag components
Add-in Express VCL bases Smart Tag libraries on the Smart Tag module that is a container for Smart Tag components of the TadxSmartTag type.
The Kind property of the TadxSmartTag component allows you to choose one of two text recognition strategies: either using a list of words in the RecognizedWords string collection or implementing a custom recognition process based on the Recognize event of the component. Use the ActionNeeded event to change the Actions collection according to the current context. The component raises the PropertyPage event when the user clicks the Property button in the Smart Tags tab (Tools / AutoCorrect Options menu) for your smart tag.
The sample smart tag project below is for Microsoft Word 2002 and 2003. If you develop for Office 2007, see a sample smart tag for Word 2007 and Excel 2007.
Step #1 – Creating a new smart tag library project
In the Borland Delphi IDE, close all opened projects, select the File | New | Others menu item, and run the Add-in Express Smart Tag Library wizard on the Add-in Express VCL tab of the New Item dialog box.

When you select the template and click OK, the Smart Tag Project wizard starts. In the wizard window, enter the name of the project, the coclass name, and the destination folder for the project.

The wizard creates and opens the Smart Tag project in the Delphi IDE.

The smart tag project includes the following items:
- The project source files (ProjectName.*)
- The type library files: binary (ProjectName.tlb) and Object Pascal unit (ProjectName_TLB.pas)
- The smart tag module (ProjectName_IMPL.pas and ProjectName_IMPL.dfm) discussed in the next step.
Step #2 – Add-in Express 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 – Add-in Express 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 Locale.

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.

Activate the Object Inspector window and specify the caption for the added smart tag in the Caption property. The value of this property becomes 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
Build and register the project (Run | Register ActiveX Server menu), restart Word or Excel, put the words recognizable by your smart tag into a document, and check if your smart tag works.

In Office 2003 - 2003, choose the Tools | AutoCorrect menu item and find your smart tag on the Smart Tags tab. In Office2007, the path to this dialog is as follows: Office button | Word Options | Add-ins | Mange | Manage Smart Tags | 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 VCL homepage

