Re: StringGrid: How to change the font colour of a cell

"smching2001" <[email protected]>
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <[email protected]>
Error encounter when I execute the code from Lloyd. Below is the 
error message:

Project Project1.exe raised exception class EAccessViolation with 
message 'Access violation at address 0045C566 in module 'PROJECT1.EXE'

The program stopped at this line:
if (stringGrid1.cells[Acol, Arow][1] = '1') and (ACol = 0) then

I'm using Delphi 6. row & col are changed to ARow & Acol respectively.

--- In [email protected], "Rory Daulton" 
<daulton@n...> wrote:
> smching2001,
> 
> > I want to change the cell font colour of the StringGrid when it 
meet
> > certain criteria.
> >
> > For example, when user enter a value of 100 in the cell, its font
> > then change to red colour.
> 
> Below is some code from Lloyd's Help File.  This changes both the 
font color
> and the background color of the cell.
> 
> Rory Daulton
> rorydaulton@e...
> Campus Crusade for Christ
> 
> 
> Q:  How do I highlight selected fields on a TStringGrid?
> 
> A:
> 
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   i: integer;
> begin
>   stringGrid1.DefaultDrawing := false;
>   with StringGrid1 do
>   begin
>     colCount := 26;
>     RowCount := 99;
>     for i := 1 to 20 do
>       cells[i, 0] := chr(i + 64);
>     for i := 0 to 99 do
>       cells[0, i + 1] := IntToStr(i);
>   end;
> end;
> 
> procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: 
Longint;
>   Rect: TRect; State: TGridDrawState);
> begin
>   if (stringGrid1.cells[col, row][1] = '1') and (Col = 0) then
>   begin
>     stringGrid1.canvas.brush.color := clMaroon;
>     stringGrid1.canvas.font.color := clWhite;
>   end
>   else
>   begin
>     stringGrid1.canvas.brush.color := clWhite;
> 
>     stringGrid1.canvas.font.color := clMaroon;
>   end;
>   stringGrid1.canvas.fillRect(rect);
>   stringGrid1.canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 3,
> StringGrid1.cells[col, row]);
> end;
> 
> { This code came from Lloyd's help file! }
> 
> 
> ---
> [This E-mail scanned for viruses by Declude Virus and Nmax "Your 
MAXimum Connection!"]
> [This E-mail scanned for spam by Declude JunkMail and Nmax "Your 
MAXimum Connection!"]


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Control Hunger EZ with fast acting oral EZ Appetite Suppressant Spray
from VitaminBoost.com. 1 Month Supply - 2oz., 80 sprays: $19.97.
http://www.challengerone.com/t/l.asp?cid=2866&lp=ezappetite3.html
http://us.click.yahoo.com/aSJFwB/XWXGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->

CodeCoffer - new Delphi code protection Tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.