恐怕得看看源码才能知道具体错在哪,
不过分析其可能性,
看看TCanvas.TextOut的实现:
procedure TCanvas.TextOut(X, Y: Integer; const Text: String);
begin
Changing;
RequiredState([csHandleValid, csFontValid, csBrushValid]);
if CanvasOrientation = coRightToLeft then Inc(X, TextWidth(Text) + 1);
Windows.ExtTextOut(FHandle, X, Y, FTextFlags, nil, PChar(Text),
Length(Text), nil);
MoveTo(X + TextWidth(Text), Y);
Changed;
end;
再看RequiredState:
procedure TCanvas.RequiredState(ReqState: TCanvasState);
var
NeededState: TCanvasState;
begin
NeededState := ReqState - State;
if NeededState <> [] then
begin
if csHandleValid in NeededState then
begin
CreateHandle;
if FHandle = 0 then
raise EInvalidOperation.CreateRes(@SNoCanvasHandle);
end;
......
end;
end;
再看SNoCanvasHandle:
SNoCanvasHandle = 'Canvas does not allow drawing';
呵呵,
应该就是它了。
估计可能就是因为Canvas的句柄被提前释放或出了其它什么意外。