Tuesday, March 1, 2011

Hello, word!

OLE automation servers are a natural part of most major Microsoft applications such as Microsoft Office products and many other popular applications, which means you can control them from your application almost as if they were a part of your program.
For example, let's take Microsoft Word 95. As you can see, it'll only take a few lines of code to make it possible to insert text to Word documents from your application (don't forget to add "OLEAuto" unit to your "uses" statement):

procedure InsertTextToWord(
sText : string );
var W : Variant;
begin
{ create an OLE object of }
{ type Word.Basic }
W := CreateOleObject( 'word.basic' );
{ call Word.Basic's Insert function }
W.Insert( sText );
end;
Using the above function, all you have to do is call it with the text you want to insert:
InsertTextToWord( 'hello, word!' );
To find out what other commands you can use to control Microsoft Word (for example) lookup its help for "WordBasic" -- the name of the macro language used to write custom applications for Word. To find out if your favorite application supports OLE automation, lookup its help for "OLE Automation."

Source : http://www.chami.com/tips/delphi/011597D.html

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum