unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, Grids, StdCtrls, Series, Printers;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    PrintDialog1: TPrintDialog;
    Button3: TButton;
    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
  I: Integer;
  j: Integer;
begin
  //wypelnianie tabeli
  with Stringgrid1 do
  for I := 0 to ColCount - 1 do
    for j := 0 to RowCount - 1 do
      Cells[i,j]:=InttoStr(1+Random(10));


end;

procedure TForm1.Button2Click(Sender: TObject);
begin
end;

//procedura drukuje zawartość komórek tabeli
procedure TForm1.Button3Click(Sender: TObject);
var zbior: textfile;
       i,j:integer;
begin
   if PrintDialog1.Execute then
   begin
     AssignPrn(zbior);
     Rewrite(zbior);
     with Printer.Canvas.Font do  //zmiana atrybutów czcionki
     begin
       Name:='Courier New';
       Style:=[fsBold];//,fsItalic];
       Size:=14;
       Color:=clGreen;
     end;
   for i:=0 to StringGrid1.RowCount-1 do
   begin
   for j:=0 to StringGrid1.ColCount-1 do
     Write(zbior,StringGrid1.Cells[j,i]:5);  //wydrukowanie zawartości komórek na 5
                                             // pozycjach
   Writeln(zbior);  //po wydrukowaniu wiersza — nowa linia
   end;
   CloseFile(zbior);
   end
   else
   Showmessage('Anulowano drukowanie');
end;


end.
