onPaint event high cpu usage [resolved]
Posted: Fri Dec 13, 2019 2:28 am
Hello, I have a client application that needs to have cell-specific text formatting (e.g., bold, font colour, background). I am using the OnPaint event, but notice that the event is continuously firing and taking up high cpu usage. I tried both settings for DoubleBuffered and that did not resolve the issue.
Please advise any workarounds. Thanks!
I am using the latest TeeGrid 2019.
In the test code below, the test label starts counting continuously and does not stop. I am not moving the mouse.
Here is the onPaint code I am using:
Please advise any workarounds. Thanks!
I am using the latest TeeGrid 2019.
In the test code below, the test label starts counting continuously and does not stop. I am not moving the mouse.
Here is the onPaint code I am using:
Code: Select all
// declare the following in the form class:
// MyData : TStringsData;
// iCount: Longint;
//
procedure TForm1.FormShow(Sender: TObject);
begin
MyData:= TStringsData.Create(3, 10); // 3 columns, 10 rows
grid.Data:= MyData;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
iCount := 0;
grid.Columns[0].OnPaint := OnPaintColumn;
grid.Columns[1].OnPaint := OnPaintColumn;
grid.Columns[2].OnPaint := OnPaintColumn;
mydata.Cells[0,0] := 'hello';
mydata.Cells[1,0] := 'world';
mydata.Cells[2,0] := '0';
mydata.Cells[0,1] := 'special';
mydata.Cells[1,1] := 'line';
mydata.Cells[2,1] := '37.45';
end;
procedure TForm1.onPaintColumn(const Sender:TColumn; var AData:TRenderData; var DefaultPaint:Boolean);
var
formatSave: TTextFormat;
begin
if aDAta.Row = 1 then
begin
with (Sender.Render as TTextRender) do
begin
formatSave := grid.Cells.Format;
defaultPaint := false;
format.Font := grid.Cells.Format.Font;
format.Font.Style := [fsBold];
adata.Painter.SetFont(format.Font);
Paint(AData);
format.Font.Style := [];
adata.Painter.SetFont(format.Font);
end;
end
else begin
defaultPaint := true;
end;
Inc(iCount);
lblStatus.Caption := timetostr(now()) + intToStr(iCount);
end;