home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Example showing how to call VarToInterface to obtain an instance of
- IDispatch. }
-
- { NOTE: This program will only work correctly if the US version of
- Microsoft Word is installed }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls;
-
- type
- TOleWordForm = class(TForm)
- bTalkWord: TButton;
- Image1: TImage;
- procedure bTalkWordClick(Sender: TObject);
- end;
-
- var
- OleWordForm: TOleWordForm;
-
- implementation
-
- {$R *.DFM}
-
- uses
- OleAuto, Ole2;
-
- var
- V: Variant;
-
- procedure TOleWordForm.bTalkWordClick(Sender: TObject);
- var
- A: IDispatch;
- I: Integer;
- begin
- V := CreateOleObject('Word.Basic');
- A := VarToInterface(V);
- try
- ShowMessage('AddRef returns: ' + IntToStr(A.AddRef));
- A.GetTypeInfoCount(I);
- ShowMessage('TypeInfoCount: ' + IntToStr(I));
- finally
- A.Release;
- end;
- if VarType(V) = varDispatch then
- ShowMessage('VarType(V) = varDispatch: True')
- else
- ShowMessage('VarType(V) = varDispatch: False');
- V.FileNew('Normal');
- V.Insert('The are no mistakes in life some people say' + Chr(13));
- V.Insert('And it''s true, sometimes, you can see it that way.' + Chr(13));
- V.Insert('People don''t live or die people just float;' + Chr(13));
- V.Insert('She''s gone with the man in the long back coat.');
- V.FileSaveAs('C:\ZIMMY.DOC');
- end;
-
- end.