The fusion technology between Delphi and Word

Source: Internet
Author: User
Tags extend ole

Microsoft Word is an integrated environment, a word processing system for Microsoft in the United States, but it's not just a word processing system that integrates Microsoft Visual Basic and can be programmed to extend the word functionality.

Microsoft Visual Basic code in Word, a Word macro, can automate some document processing by writing Word macros, such as automatic backup of documents, saving, and so on, to extend the functionality of Word documents, so that you can make the most of the features of Word. Even make word a part of your software. Word's macros have a good part because it helps us automate the document, but Word macros are not purely advantageous, and sometimes it can compromise our documents, computer systems, and even the network, from the very beginning Taiwan NO1 macro virus to the current Melissa macro virus, From the very beginning of the simple hint, exhaustion of system resources to the current hair e-mail, send personal information to the network, and even to the hard disk Autoexec.bat (Automatic batch file) to add deltree C:-y, destroying the entire Windows system.

COM technology embedded in Word

Word is the best software for COM technology, which seems to be a bit extreme, but the powerful programming interface technology that Word provides can be that we control any part of Word by program. Whether it's open, save, print, or automatically draw a table in a document.

Through programming software, can be flexible to manipulate word, here only to Borland Delphi For example, for detailed description:

1. The method of calling Word Software/file in Delphi

Call word software in Word, and there are three ways to embed word in the Delphi control Tolecontainer

A. Use the servers control provided by Delphi to invoke Word, using the properties of Word

B. Through the real COM technology, the Office software directory in the file Msword9.olb all the class library into the Delphi,

C. Use Createoleobject to start Word, and then to control word in OLE mode.

2, the difficulty of several methods to determine the degree of

A. Through the Delphi control Tolecontainer to embed Word

This is the simplest OLE embedding that can be invoked directly from a Word document, and you can start the Word document directly using Tolecontainer.run. And this start of the Word document and the Delphi program is a whole (from the interface), but it has insurmountable shortcomings, that is, can not control the Word document through Delphi, also can not achieve the purpose of flexible manipulation of word.

B. Use the servers control provided by Delphi to invoke word and use the properties of Word.

Use the Delphi servers control to manipulate word, in programming Delphi can implement code hints, overall see can better realize Delphi control of Word, However, there are some features of word that cannot be invoked in Delphi (such as the VBA macro code you write yourself).

and implementation of the function of the VBA code in the optional parameters in the Delphi call must be added, otherwise, even the compilation can not pass.

This way the word and Delphi program are started in two forms. This approach can only serve as a reference.

C. Through the real COM technology, the Office software directory in the file Msword9.olb all the class library into Delphi, the use of COM technology programming, using real COM technology, the Msword9.old file class library to import, and then use the COM technology.

A servers control that uses Delphi as a whole is slightly more troublesome than a servers control, with the same advantages and disadvantages as the servers control.

D. Use Createoleobject to start Word, and then to control word in OLE mode.

The idea is to use createoleobjects to call word, which is actually OLE, but this way you can really control the word file completely and be able to use all of the properties of word, including your own VBA macro code.

Compared to servers controls and COM technologies, this method can really use the various properties of word, as well as writing its own code in VBA, and the default code does not need to be used.

This method starts with the word and Delphi program is divided into two forms.

The disadvantage is that the use of this method does not have Delphi code hints, all exception processing need to write their own, may be written when the exploratory knowledge more.

Word Macro Editor

How to get into the Word Macro Editor: Tool-> macro->visual basic Editor, access to the Visual basic Editor interface. Word's Visual Basic Editor interface is essentially the same as the real Visual Basic Editor, and is no longer detailed here.

In VBA code, you can add user forms, modules, and class modules. The concepts of user forms, modules, and class modules are exactly the same as Visual Basic. The annotation is also identical to Visual Basic.

You can rest the cursor on any of the subroutines of a form or module and press "F5" to run the current subroutine directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.