...
var
dt: array[0..10] of array[0..7] of integer =
((0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0),
(0,0,1,1,1,2,2,0),
(0,0,1,1,1,2,2,0),
(0,0,1,1,1,2,2,0),
(0,0,0,1,1,2,2,0),
(0,0,0,1,1,2,0,0),
(0,0,0,1,1,0,0,0),
(0,0,0,3,3,0,0,0),
(0,0,0,3,0,0,0,0),
(0,0,0,0,0,0,0,0));
type
TColorRowColObj = class(TObject)
public
clr: integer;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: integer;
begin
for i := 0 to StringGrid1.RowCount do
for j := 0 to StringGrid1.ColCount do
begin
StringGrid1.Objects[j, i]:= TColorRowColObj.Create;
(StringGrid1.Objects[j, i] as TColorRowColObj).clr:= dt[i, j];
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; vCol, vRow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with (Sender as TStringGrid), Canvas do
begin
case (Objects[vCol, vRow] as TColorRowColObj).clr of
0: Brush.Color:= clWhite;
1: Brush.Color:= clYellow;
2: Brush.Color:= clGreen;
3: Brush.Color:= clRed;
end;{case}
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, Cells[vCol, vRow]);
end;
end;