unit metpaint;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

const ilosc_liczb=6;
type
  tab=array[1..ilosc_liczb] of integer;
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
     t:tab;
implementation

{$R *.dfm}

procedure Wypelnij;
var
  I, J, K: Integer;
begin
  K:=0;
  with Form1.StringGrid1 do
    for I := 0 to ColCount - 1 do
      for J:= 0 to RowCount - 1 do
      begin
         K:=K+1;
         Cells[J,I] := IntToStr(K);
      end

end;

procedure Totolotek(var t: tab);
var i,j,k:integer;
begin
 i:=1;
  repeat
    t[i]:=1+Random(49); {zakres wartosci generowanych liczb}
    k:=i;
    for j:=1 to k-1 do {petla spr. czy nowa liczba jest juz w tablicy}
       if t[j]=t[k] then i:=i-1;
    i:=i+1;
  until i=ilosc_liczb+1;
end;


procedure TForm1.FormCreate(Sender: TObject);
var Rect:TRect;
begin
  Randomize;
  //kasowanie zaznaczenia wybranej komórki
  //Stringgrid1.Selection:=TGridRect(Rect(-1,-1,-1,-1));

end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Wypelnij;
  Totolotek(t);
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
    i:integer;
begin
  //zmiana tla komorki w lewym gornym rogu
  if (ACol=0)and (ARow=0) then
  with StringGrid1 do
  begin
    Canvas.Brush.Color:=clWhite;
    Canvas.FillRect(Rect);
    Canvas.Font.Color:=clBlack;
    Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[0,0]);
  end;


  //wypelnienie zoltym kolorem komorek wybranych losowo
  with StringGrid1 do
   for i:= 1 to ilosc_liczb do
    if (ACol=(t[i]-1) mod 7)  and (ARow=(t[i]-1) div 7)  then
    begin
      Canvas.Brush.Color:=clLime;
      Canvas.FillRect(Rect);
      Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]); //Cells[(t[i]-1) mod 7,(t[i]-1) div 7]);
    end;
end;

end.
