home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Runimage / DELPHI20 / DEMOS / DOC / VARTOINT / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-10  |  1.4 KB  |  62 lines

  1. unit Main;
  2.  
  3. { Example showing how to call VarToInterface to obtain an instance of
  4.   IDispatch. }
  5.  
  6. { NOTE: This program will only work correctly if the US version of
  7.   Microsoft Word is installed }
  8.  
  9. interface
  10.  
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   StdCtrls, ExtCtrls;
  14.  
  15. type
  16.   TOleWordForm = class(TForm)
  17.     bTalkWord: TButton;
  18.     Image1: TImage;
  19.     procedure bTalkWordClick(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   OleWordForm: TOleWordForm;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. uses
  30.   OleAuto, Ole2;
  31.  
  32. var
  33.   V: Variant;
  34.  
  35. procedure TOleWordForm.bTalkWordClick(Sender: TObject);
  36. var
  37.   A: IDispatch;
  38.   I: Integer;
  39. begin
  40.   V := CreateOleObject('Word.Basic');
  41.   A := VarToInterface(V);
  42.   try
  43.     ShowMessage('AddRef returns: ' + IntToStr(A.AddRef));
  44.     A.GetTypeInfoCount(I);
  45.     ShowMessage('TypeInfoCount: ' + IntToStr(I));
  46.   finally
  47.     A.Release;
  48.   end;
  49.   if VarType(V) = varDispatch then
  50.     ShowMessage('VarType(V) = varDispatch: True')
  51.   else
  52.     ShowMessage('VarType(V) = varDispatch: False');
  53.   V.FileNew('Normal');
  54.   V.Insert('The are no mistakes in life some people say' + Chr(13));
  55.   V.Insert('And it''s true, sometimes, you can see it that way.' + Chr(13));
  56.   V.Insert('People don''t live or die people just float;' + Chr(13));
  57.   V.Insert('She''s gone with the man in the long back coat.');
  58.   V.FileSaveAs('C:\ZIMMY.DOC');
  59. end;
  60.  
  61. end.
  62.