title: delphi : how can I change color of a cell in string grid
body: <p>I want to change background color ( not font ) of a cell in string grid in delphi .</p>
  
  <p>Just one cell not a row or a column.</p>
  
  <p>Can I?</p>
  
  <hr>
  
  <p>RRUZ : your procedure is correct and works but in my procedure doesn't work. </p>
  
  <p>My procedure:</p>
  
  <p>x is a global array of integer</p>
  
  <pre><code>procedure TF_avalie_salon.StringGrid1DrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
      var   S: string;
  begin
      S := StringGrid1.Cells[ACol, ARow];
      StringGrid1.Canvas.FillRect(Rect);
      SetTextAlign(StringGrid1.Canvas.Handle, TA_CENTER);
      StringGrid1.Canvas.TextRect(Rect,Rect.Left + (Rect.Right - Rect.Left) div 2, Rect.Top + 2, S);
      if (ARow&lt;&gt;0 )AND(acol&lt;&gt;0)AND(gridclick=true) then
      begin
          try
            gridclick:=false;
            x[acol+((strtoint(Edit_hafte.Text)-1)*7),arow]:=strtoint(StringGrid1.Cells[ACol, ARow]);
          except
            x[acol+((strtoint(Edit_hafte.Text)-1)*7),arow]:=0;
            StringGrid1.Cells[acol,arow]:='0';
            with TStringGrid(Sender) do
            begin
              Canvas.Brush.Color := clGreen;
              Canvas.FillRect(Rect);
              Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol, ARow]);
            end;
          end;
      end;
  end;
  </code></pre>
  
  <hr>
  
  <p>When I use Canvas.Brush.Color with below code , Canvas.Brush.Color doesn't work. If I inactive below code I can change the cells color. But I need both.</p>
  
  <pre><code>    S := StringGrid1.Cells[ACol, ARow];
      StringGrid1.Canvas.FillRect(Rect);
      SetTextAlign(StringGrid1.Canvas.Handle, TA_CENTER);
      StringGrid1.Canvas.TextRect(Rect,Rect.Left + (Rect.Right - Rect.Left) div 2, Rect.Top + 2, S);
  </code></pre>