1. Home
  2. Computing & Technology
  3. Delphi Programming

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

By Zarko Gajic, About.com

3 of 7

Launching (Automating) Word Silently

"Server" Components in Delphi

"Server" Components in Delphi

The example in this article will use "server" components provided with Delphi. If you have some earlier version of Delphi I suggest you should use early binding with Word type library.
uses Word_TLB;
...
var
  WordApp : _Application;
  WordDoc : _Document;
  VarFalse : OleVariant;
begin
  WordApp := CoApplication.Create;
  WordDoc := WordApp.Documents.Add(EmptyParam, EmptyParam) ;
{
  spell check code as described
  later in this article
  }

  VarFalse:=False;
  WordApp.Quit(VarFalse, EmptyParam, EmptyParam) ;
end;
Many parameters passed to Word methods are defined as optional parameters. When using interfaces (typep libraries), Delphi does not allow you to left out any optional arguments. Delphi provides a variable which can be used for optional parameters that are not being used called EmptyParam.

To automate Word with a Variant variable (late binding) use this code:

uses ComObj;
...
var
  WordApp, WordDoc: Variant;
begin
  WordApp := CreateOleObject('Word.Application') ;
  WordDoc := WordApp.Documents.Add;
  {
  spell check code as described
  later in this article
  }

  WordApp.Quit(False)
end;
When using late binding, Delphi allows you to left out any optional arguments when calling methods (like Quit). You call methods and properties, as long as you know what they are.

The "Easy" Way

As mentioned, newer Delphi version simplify the use of MS Word as an Automation server by wrapping methods and properties into components. Since many parameters passed to Word methods are defined as optional, Delphi overloads these methods and defines several versions with varying numbers of parameters.
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Advanced Delphi Techniques
  5. OLE / COM / Automation
  6. Automation
  7. Word Automation in Delphi: Early Binding vs. Late Binding

©2009 About.com, a part of The New York Times Company.

All rights reserved.