Saturday, December 10, 2005


The 200 kloc project I'm porting uses only a few third-party CLX components on Delphi 7. The most used by far are TAdvStringGrid (Advanced String Grid) and Synapse (serial communication). The latter is already ported to Lazarus, so I focused on the standard TStringGrid from LCL.

In my code, the event OnGetCellColor (from TAdvStringGrid) is used to change the look of the Cell depending on some conditions. The AlternateColor property solved part of my problems, but I needed to check the Cell's content before it's drawn. Then, after a few searches, I've found OnPrepareCanvas. A simple code to put negative numbers in red looks like this:

procedure TForm1.StringGrid1PrepareCanvas(sender: TObject;
Col, Row: Integer; aState: TGridDrawState);
if not (gdfixed in aState) then
if Pos('-',StringGrid1.Cells[Col,Row]) = 0 then begin
StringGrid1.Canvas.Font.Color := clBlue;
end else begin
StringGrid1.Canvas.Font.Color := clRed;
The standard TStringGrid from LCL has all I need: the project is one step closer to be ported. Thanks Jesus Reyes Aguilar for the great work!

No comments: