在触发creatsl事件时想把stringgrid的OnDrawCell事件发生但是编译通不过,希望高手们把他改正。procedure TStore.creatsl;
begin
  sgname.OnDrawCell:=sgrowcolor;
end;procedure TStore.sgrowcolor(ACol,ARow:Integer;Rect:TRect; State:TGridDrawState);
var
i:integer;
begin
  for I := 0 to sgname.ColCount- 1 do begin
     if arow =0 then 
     sgname.Canvas.Brush.Color:=clskyblue;
  end;
  sgname.Canvas.FillRect(Rect);
  sgname.Canvas.TextOut(Rect.Left,Rect.Top,sgname.Cells[ACol,ARow]);
end;

解决方案 »

  1.   

    procedure   TStore.creatsl; 
    begin 
        sgname.OnDrawCell:=sgrowcolor(//这里要有参数); 
    end; procedure   TStore.sgrowcolor(ACol,ARow:Integer;Rect:TRect;   State:TGridDrawState); 
    var 
    i:integer; 
    begin 
        for   I   :=   0   to   sgname.ColCount-   1   do   begin 
              if   arow   =0   then   
              sgname.Canvas.Brush.Color:=clskyblue; 
        end; 
        sgname.Canvas.FillRect(Rect); 
        sgname.Canvas.TextOut(Rect.Left,Rect.Top,sgname.Cells[ACol,ARow]); 
    end;
      

  2.   

    procedure TStore.sgrowcolor(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);要写成这样才行的.
      

  3.   

    楼上正解。
    sgname.OnDrawCell:=sgrowcolor这里不用参数的
    只要保证sgrowcolor的参数跟这个控件标准的OnDrawCell事件参数一样就行了。
      

  4.   

    1. TStore.sgrowcolor的函数头改为: procedure TStore.sgrowcolor(Sender:TObject; ACol,ARow:Integer; Rect:TRect; State:TGridDrawState); 2. sgname.OnDrawCell:=sgrowcolor;  这一句的功能是设置sgname对象的OnDrawCell事件处理函数, 并不会调用sgrowcolor函数的。要调用的话,需要显式地写成 sgrowcolor(...参数...);
      

  5.   

    直接调用sgrowcolor,传参数进去么就好了