home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Install / DATA.Z / AUTOCTL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-11  |  2.6 KB  |  108 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, 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 OleAuto;
  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(16);
  50.   except
  51.     try
  52.       { for German Microsoft Word the procedure call is translated }
  53.       Lang := MsWord.AnwInfo(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 + ',' +
  73.           Query1OrderNo.AsString + ',' + Query1SaleDate.AsString + #13;
  74.         Inc(L);
  75.         Next;
  76.       end;
  77.       if (Lang = 'English (US)') or (Lang = 'English (UK)') then
  78.       begin
  79.         MsWord.AppShow;
  80.         MSWord.FileNew;
  81.         MSWord.Insert(S);
  82.         MSWord.LineUp(L, 1);
  83.         MSWord.TextToTable(ConvertFrom := 2, NumColumns := 3);
  84.       end;
  85.       if Lang = 'Franτais' then
  86.       begin
  87.         MsWord.FenAppAfficher;
  88.         MsWord.FichierNouveau;
  89.         MSWord.Insertion(S);
  90.         MSWord.LigneVersHaut(L, 1);
  91.         MSWord.TexteEnTableau(ConvertirDe := 2, NbColonnesTableau := 3);
  92.       end;
  93.       if (Lang = 'German (De)') or (Lang = 'Deutsch') then
  94.       begin
  95.         MsWord.AnwAnzeigen;
  96.         MSWord.DateiNeu;
  97.         MSWord.Einfⁿgen(S);
  98.         MSWord.ZeileOben(L, 1);
  99.         MSWord.TextInTabelle(UmWandelnVon := 2, AnzSpalten := 3);
  100.       end;
  101.     finally
  102.       Close;
  103.     end;
  104.   end;
  105. end;
  106.  
  107. end.
  108.