home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / ACTIVEX / OLEAUTO / AUTOCTRL / AUTOCTL.PAS < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  3KB  |  110 lines

  1. unit AutoCtl;
  2.  
  3. { This program demonstrates Delphi's automation control abilities by
  4.   inserting a query into a document, using Microsoft Word as an automation
  5.   server }
  6.  
  7. interface
  8.  
  9. uses Windows, Classes, SysUtils, Graphics, Forms, Controls, DB, DBGrids,
  10.   DBTables, Grids, StdCtrls, ExtCtrls, ComCtrls, Dialogs;
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     Query1: TQuery;
  15.     Panel1: TPanel;
  16.     InsertBtn: TButton;
  17.     Query1Company: TStringField;
  18.     Query1OrderNo: TFloatField;
  19.     Query1SaleDate: TDateTimeField;
  20.     Edit1: TEdit;
  21.     Label1: TLabel;
  22.     procedure InsertBtnClick(Sender: TObject);
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. uses ComObj;
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure TForm1.InsertBtnClick(Sender: TObject);
  35. var
  36.   S, Lang: string;
  37.   MSWord: Variant;
  38.   L: Integer;
  39. begin
  40.   try
  41.     MsWord := CreateOleObject('Word.Basic');
  42.   except
  43.     ShowMessage('Could not start Microsoft Word.');
  44.     Exit;
  45.   end;
  46.   try
  47.     { Return Application Info. This call is the same for English and
  48.      French Microsoft Word. }
  49.     Lang := MsWord.AppInfo(Integer(16));
  50.   except
  51.     try
  52.       { for German Microsoft Word the procedure name is translated }
  53.       Lang := MsWord.AnwInfo(Integer(16));
  54.     except
  55.       { if this procedure does not exist there is a different translation of
  56.        Microsoft Word }
  57.        ShowMessage('Microsoft Word version is not German, French or English.');
  58.        Exit;
  59.     end;
  60.   end;
  61.   with Query1 do
  62.   begin
  63.     Form1.Caption := Lang;
  64.     Close;
  65.     Params[0].Text := Edit1.Text;
  66.     Open;
  67.     try
  68.       First;
  69.       L := 0;
  70.       while not EOF do
  71.       begin
  72.         S := S + Query1Company.AsString + ListSeparator +
  73.           Query1OrderNo.AsString + ListSeparator + Query1SaleDate.AsString + #13;
  74.         Inc(L);
  75.         Next;
  76.       end;
  77.       if (Lang = 'English (US)') or (Lang = 'English (United States)') or
  78.          (Lang = 'English (UK)') or (Lang = 'German (Standard)') or
  79.          (Lang = 'French (Standard') then
  80.       begin
  81.         MsWord.AppShow;
  82.         MSWord.FileNew;
  83.         MSWord.Insert(S);
  84.         MSWord.LineUp(L, 1);
  85.         MSWord.TextToTable(ConvertFrom := 2, NumColumns := 3);
  86.       end;
  87.       if Lang = 'Franτais' then
  88.       begin
  89.         MsWord.FenAppAfficher;
  90.         MsWord.FichierNouveau;
  91.         MSWord.Insertion(S);
  92.         MSWord.LigneVersHaut(L, 1);
  93.         MSWord.TexteEnTableau(ConvertirDe := 2, NbColonnesTableau := 3);
  94.       end;
  95.       if (Lang = 'German (De)') or (Lang = 'Deutsch') then
  96.       begin
  97.         MsWord.AnwAnzeigen;
  98.         MSWord.DateiNeu;
  99.         MSWord.Einfⁿgen(S);
  100.         MSWord.ZeileOben(L, 1);
  101.         MSWord.TextInTabelle(UmWandelnVon := 2, AnzSpalten := 3);
  102.       end;
  103.     finally
  104.       Close;
  105.     end;
  106.   end;
  107. end;
  108.  
  109. end.
  110.