unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 i,j:integer;
begin
   StringGrid1.ColCount:=7;
   StringGrid1.RowCount:=20;
   for i:=0 to StringGrid1.RowCount-1 do
    begin
     for j:=0 to StringGrid1.ColCount-1 do
      begin
       StringGrid1.Cells[j,i]:=IntToStr(random(100));
      end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   randomize;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
   if StringGrid1.Cells[ACol,ARow]<>'' then
    begin
     if StrToInt(StringGrid1.Cells[ACol,ARow])>=50 then
      begin
       StringGrid1.Canvas.Brush.Color:=clRed;
       StringGrid1.Canvas.FillRect(Rect);
       StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[Acol,Arow]);
      end;
     end;
   if StringGrid1.Cells[ACol,ARow]<>'' then
    begin
     if StrToInt(StringGrid1.Cells[ACol,ARow])<=10 then
      begin
       StringGrid1.Canvas.Brush.Color:=clGreen;
       StringGrid1.Canvas.FillRect(Rect);
       StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[Acol,Arow]);
      end;
     end;
   if StringGrid1.Cells[ACol,ARow]<>'' then
    begin
     if (StrToInt(StringGrid1.Cells[ACol,ARow])>10)
        and (StrToInt(StringGrid1.Cells[ACol,ARow])<50) then
      begin
       StringGrid1.Canvas.Brush.Color:=clYellow;
       StringGrid1.Canvas.FillRect(Rect);
       StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[Acol,Arow]);
      end;
     end;
end;

end.
