怎么动态改变stringgrid的cell的颜色

如何动态改变stringgrid的cell的颜色
我看了很多网上的介绍,基本上都是调用OnDrawCell函数,但是好像都无法实现我要的功能
OnDrawCell大概是在grid刷新的时候才调用,并且前提好像也是grid的cell的值已经赋值过了
我的需求是我在给一个cell赋值的同时,也改变这个cell的颜色,这个cell的row,col是动态计算得到的
而且,这种cell不仅仅只有一个,会有很多,row,col值也都不一样
如果用OnDrawCell函数,还需要判断row和col的值是不是动态计算得到的,如果是这样我不得不定义一个数组变量来保存所有的cell的row和col值,还有每个cell的颜色值,因为每个cell的颜色不一定一样
这该如何做?

------解决方案--------------------
procedure TForm1.spSkinStringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
with Sender as TspSkinStringGrid do begin
if ACol in [0..3] then
begin //偶数row
Canvas.Brush.Color := clYellow; //底色
end
else if ACol in [4..5] then
begin
Canvas.Brush.Color := clRed;
end;
Canvas.FillRect(Rect); //绘底色
Canvas.Brush.Style:=bsClear;
canvas.textout(Rect.Left+(Rect.Right-Rect.Left-canvas.TextWidth(cells[Acol,ARow]))div 2,Rect.Top+(Rect.Bottom-Rect.Top-canvas.TextHeight(cells[Acol,ARow]))div 2,cells[Acol,ARow]);
end;
end;

还可以在上述事件里面根据表格数据来动态调整颜色,比如数据小于某值和大于某值的颜色不同!
然后在你每次改变表格数据时,调用一下: spSkinStringGrid1.Repaint


目前,据我所知,这是使用delphi自带方法中唯一的方法。
------解决方案--------------------
这个是画图的
procedure TForm7.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ((ACol<>2) or (Arow=0)) then exit;

if AROW > MyRowCount + 1 then exit;

with Sender as TDrawGrid do
begin
Canvas.Brush.Color := clActiveButton;
if (GlobalData^.RealData[mnlxh[ARow-1]] > 0.5) then
StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, redled.Picture.Graphic)
else
StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, Blueled.Picture.Graphic);
if gdFocused in State then
Canvas.DrawFocusRect(Rect);
end;
end;
------解决方案--------------------
探讨
to mwy654321
我在以上的帖子也说过
一种解决方案是我定义一个数组,保存所有动态计算得到的row,col和color,然后在DrawCell函数中循环查找对应的row和col,最后显示出相应的color
不过,这种做法耗时,也不合理。DrawCell函数是对所有的cell都会调用的,每次都循环查找,太耗时了

后来,我自己也写了一个画图函数
不过,每次画完后,整个grid又被……