unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  gCount = 4;
var
  gArray : TByteDynArray;
  CurHand,CurArrow : HCURSOR;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  can : TCanvas;
  w,h : Integer;
  l,t : Integer;
  sss : String;
begin
  can := (Sender as TStringGrid).Canvas;
  if gdSelected in State then can.Brush.Color := RGB(240,240,240)
                         else can.Brush.Color := clWindow;
  can.FillRect(Rect);
  if acol=1 then
  begin
    case garray[arow] of
      0 : begin
            sss := 'Неактивно';
            can.Font.Style := [];
            can.Font.Color := clBlack;
          end;
      1 : begin
            sss := 'Стоп';
            can.Font.Style := [fsUnderline];
            can.Font.Color := clRed;
          end;
      2 : begin
            sss := 'Старт';
            can.Font.Style := [fsUnderline];
            can.Font.Color := clGreen;
          end;
    end;
    w := can.TextWidth(sss);
    h := can.TextHeight(sss);
    l := ((Rect.Right-Rect.Left)-w) div 2;
    t := ((Rect.Bottom-Rect.Top)-h) div 2;
    can.TextRect(Rect,Rect.Left+l,Rect.Top+t, sss);
  end
            else
  begin
    can.Font.Style := [];
    can.Font.Color := clBlack;
    sss := StringGrid1.Cells[acol,arow];
//    w := can.TextWidth(sss);
    h := can.TextHeight(sss);
//    l := ((Rect.Right-Rect.Left)-w) div 2;
    t := ((Rect.Bottom-Rect.Top)-h) div 2;
    can.TextRect(Rect,Rect.Left+2,Rect.Top+t, sss);
  end;
  
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  j: integer;
begin
  Randomize;
  SetLength(gArray, gCount);
  for j:=0 to pred(gCount) do
    garray[j] := random(3);
  StringGrid1.RowCount := gcount;
  for j:=0 to pred(gcount) do
  begin
    StringGrid1.Cells[0, j] := 'Строка #'+Inttostr(j+1);
    StringGrid1.Cells[1, j] := inttostr(garray[j]);
  end;
  curhand  := LoadCursor(0, IDC_HAND);
  curarrow := LoadCursor(0, IDC_ARROW);
end;

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var c,r  : Integer;
    hcur : HCURSOR;
begin
  StringGrid1.MouseToCell(x,y,c,r);
  if (c=1) and (garray[r]<>0) then hcur := curhand
                              else hcur := curarrow;
  SetCursor(hcur);
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  StringGrid1MouseMove(Sender, [], x,y);
end;

end.
