打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Word Automation in Delphi: Early Binding vs. Late Binding

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

By

3 of 7

Launching (Automating) Word Silently

"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.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Word模板的制作方法和内容定位识别技术 - hcx
Delphi和Word编程集锦
Delphi控制Word编程手记
Delphi操作word的基本用法
C#获取Word文档页数,并跳转到指定的页面获取页面信息
C# VS2012操作word文档 (一).创建文档
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服