Canvas does not allow drawing
Posted: Mon Nov 09, 2009 6:34 pm
I am getting "Canvas does not allow drawing" on the following line:
Line:
[code]
Result := Round((FWidth / 256) * Canvas.TextWidth('8'));
[/code]
Source:
[code]
function TXLSColumn.GetPixelWidth: integer;
var
Canvas: TCanvas;
F: TFont;
begin
Canvas := TCanvas.Create;
Canvas.Handle := GetDC(0);
try
F := TFont.Create;
try
FFormats.Fonts[0].CopyToTFont(F);
Canvas.Font.Assign(F);
Result := Round((FWidth / 256) * Canvas.TextWidth('8'));
finally
F.Free;
end;
finally
Canvas.Free;
end;
end;
[/code]
Do you know what is causing this and how to fix it?
Maybe ReleaseDC should be called?
Line:
[code]
Result := Round((FWidth / 256) * Canvas.TextWidth('8'));
[/code]
Source:
[code]
function TXLSColumn.GetPixelWidth: integer;
var
Canvas: TCanvas;
F: TFont;
begin
Canvas := TCanvas.Create;
Canvas.Handle := GetDC(0);
try
F := TFont.Create;
try
FFormats.Fonts[0].CopyToTFont(F);
Canvas.Font.Assign(F);
Result := Round((FWidth / 256) * Canvas.TextWidth('8'));
finally
F.Free;
end;
finally
Canvas.Free;
end;
end;
[/code]
Do you know what is causing this and how to fix it?
Maybe ReleaseDC should be called?