unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleServer, ComObj, ComCtrls, WordXP;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    OpenDialog1: TOpenDialog;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    RichEdit1: TRichEdit;
    FontDialog1: TFontDialog;
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=CreateOleObject('Word.Application');
//WordApp:=GetActiveOleObject('Word.Application');
WordApp.Visible:=True;
WordApp.Documents.Add;
end;

procedure TForm1.Button2Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
if OpenDialog1.Execute then
  WordApp.Documents.Open(OpenDialog1.FileName);
Label1.Caption:=WordApp.ActiveDocument.Name;
end;

procedure TForm1.Button3Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
WordApp.ActiveDocument.CheckSpelling;
//WordApp.ActiveDocument.PrintPreview;
//WordApp.ActiveDocument.PrintOut;
end;

procedure TForm1.Button4Click(Sender: TObject);
var WordApp,Zakres :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
//Zakres:=WordApp.ActiveDocument.Range(0,0);
Zakres:=WordApp.Selection;
Zakres.Text:=Edit1.Text;
Zakres.Select;
end;

procedure TForm1.Button5Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
WordApp.ActiveDocument.Save;
//WordApp.ActiveDocument.SaveAs('dokument.doc');
end;

procedure TForm1.Button6Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
WordApp.ActiveDocument.Range.Copy; //kopiowanie
WordApp.ActiveDocument.Range.Select; //zaznaczenie
end;

procedure TForm1.Button7Click(Sender: TObject);
var WordApp :Variant;
begin
WordApp:=GetActiveOleObject('Word.Application');
RichEdit1.Text:=WordApp.ActiveDocument.Range;
end;

procedure TForm1.Button8Click(Sender: TObject);
var
  WordApp,Czcionka :Variant;
  Styl :TFontStyles;
begin
WordApp:=GetActiveOleObject('Word.Application');
//Czcionka:=WordApp.ActiveDocument.Range.Font;
Czcionka:=WordApp.Selection.Font;
if FontDialog1.Execute then
  begin
  Czcionka.Bold:=Integer(fsBold in FontDialog1.Font.Style);
  Czcionka.Italic:=Integer(fsItalic in FontDialog1.Font.Style);
  Czcionka.Underline:=Integer(fsUnderline in FontDialog1.Font.Style);
  Czcionka.Strikethrough:=Integer(fsStrikeOut in FontDialog1.Font.Style);
  Czcionka.Name:=FontDialog1.Font.Name;
  Czcionka.Size:=FontDialog1.Font.Size;
  case FontDialog1.Font.Color of
      clBlack: Czcionka.ColorIndex:=1;
      clBlue:  Czcionka.ColorIndex:=2;
      clAqua: Czcionka.ColorIndex:=3;
      clLime : Czcionka.ColorIndex:=4;
      clFuchsia: Czcionka.ColorIndex:=5;
      clRed: Czcionka.ColorIndex:=6;
      clYellow: Czcionka.ColorIndex:=7;
      clWhite: Czcionka.ColorIndex:=8;
      clNavy: Czcionka.ColorIndex:=9;
      clTeal: Czcionka.ColorIndex:=10;
      clGreen: Czcionka.ColorIndex:=11;
      clPurple: Czcionka.ColorIndex:=12;
      clMaroon: Czcionka.ColorIndex:=13;
      clOlive: Czcionka.ColorIndex:=14;
      clGray: Czcionka.ColorIndex:=15;
      clSilver: Czcionka.ColorIndex:=16;
      end;
  end;
end;

end.
