unit CreateOleObj;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtnrs, ExtCtrls, ComObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button: TButton;
    procedure ButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: CreateOleObject
// Routine: ComObj.CreateOleObject
// Routine: OleAuto.CreateOleObject

//BeginCode
{
The following code shows an example of how to create an Ole Object and how to
perform specific operations.
}
procedure TForm1.ButtonClick(Sender: TObject);
var
  WordApp, NewDoc: Variant;
begin
  { Creates a Microsoft Word application. }
  WordApp := CreateOleObject('Word.Application');
  { Creates a new Microsoft Word document. }
  NewDoc := WordApp.Documents.Add;
  { Inserts the text 'Hello World!' in the document. }
  WordApp.Selection.TypeText('Hello World!');
  { Saves the document on the disk. }
  NewDoc.SaveAs('my_new_document.doc');
  { Closes Microsoft Word. }
  WordApp.Quit;
  { Releases the interface by assigning the Unassigned constant to the Variant variables. }
  NewDoc := Unassigned;
  WordApp := Unassigned;
end;
//EndCode
//EndExample: CreateOleObject
end.
