1. Technology

Spell Checking from Delphi code using MS Word - Office Automation in Delphi


4 of 7

The Spell Check Project - TWordApplication, TWordDocument
The Spell Project at Design-Time

The Spell Project at Design-Time

To build a spell checking project we'll need two forms: one used to edit the text and the other to see the spelling suggestions... but, let's go from the beginning.

Start Delphi. Create a new project with one blank form (form1, by default). This will be the main form in the spell checking with MS Word project. Add one TMemo (Standard tab) and two TButtons to the form. Add some text to the Memo filling the Lines property. Of course, with some typo errors. Select the Servers tab and add TWordApplication and TWordDocument to the form. Change the name of TWordApplication component from WordApplication1 to WordApp, WordDocument1 to WordDoc.

TWordApplication, TWordDocument

When automating Word, we use properties and methods of the Application object to control or return application­ wide attributes, to control the appearance of the application window, and to get to the rest of the Word object model.

The published property ConnectKind is used to control whether we connect to a newly launched Word instance or to an existing instance that is already running. Set ConnectKind to ckRunningInstance.

When we open or create a file in Word, we create a Document object. A common task when using automating Word is to specify an area in a document and then do something with it, such as insert text and spell check it. An object that represents a contiguous area in a document is called Range.

©2014 About.com. All rights reserved.