Background: Windows 64-bit application, Firemonkey, Delphi XE7
I have about 10 TStringGrid components and all of which are using the same onDrawColumnCell to change cell colors when the Value in the cells is not ‘Normal.’
I am using the following code, but the severe memory leaks happens if the red cells are displayed on the screen.(if I roll the page away where no red cell is shown, no memory is leaked).
procedure TForm.grid_DrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: integer; const Value: TValue; const State: TGridDrawStates);
var
RowColor: TBrush;
begin
RowColor := TBrush.Create(TBrushKind.Solid, TAlphacolors.Alpha);
if (Value <> ‘Normal’) then
RowColor.Color := TAlphacolors.Red
else
RowColor.Color := TAlphacolors.Null;
Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);
{ perform default drawing }
TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
Value, State);
end;
Does anyone know how to solve the memory leak problem?
Thanks