LCL: added warning when painting outside of paint message

git-svn-id: trunk@25700 -
This commit is contained in:
mattias 2010-05-27 16:02:21 +00:00
parent 924a185cfa
commit 57e6a22d2c
3 changed files with 26 additions and 2 deletions

View File

@ -258,6 +258,7 @@ type
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure FreeHandle;override; procedure FreeHandle;override;
function ControlIsPainting: boolean;
property Control: TControl read FControl write SetControl; property Control: TControl read FControl write SetControl;
end; end;
@ -822,7 +823,8 @@ type
cfBaseBoundsValid, cfBaseBoundsValid,
cfPreferredSizeValid, cfPreferredSizeValid,
cfPreferredMinSizeValid, cfPreferredMinSizeValid,
cfOnChangeBoundsNeeded cfOnChangeBoundsNeeded,
cfProcessingWMPaint
); );
TControlFlags = set of TControlFlag; TControlFlags = set of TControlFlag;
@ -1305,6 +1307,7 @@ type
function IsVisible: Boolean; virtual;// checks parents too function IsVisible: Boolean; virtual;// checks parents too
function IsControlVisible: Boolean; virtual;// does not check parents function IsControlVisible: Boolean; virtual;// does not check parents
function FormIsUpdating: boolean; virtual; function FormIsUpdating: boolean; virtual;
function IsProcessingPaintMsg: boolean;
procedure Hide; procedure Hide;
procedure Refresh; procedure Refresh;
procedure Repaint; virtual; procedure Repaint; virtual;

View File

@ -628,6 +628,11 @@ begin
Result := Assigned(Parent) and Parent.FormIsUpdating; Result := Assigned(Parent) and Parent.FormIsUpdating;
end; end;
function TControl.IsProcessingPaintMsg: boolean;
begin
Result:=cfProcessingWMPaint in FControlFlags;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TControl.LMCaptureChanged TControl.LMCaptureChanged
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -1612,6 +1617,15 @@ begin
end; end;
end; end;
end; end;
if TheMessage.Msg=LM_PAINT then begin
Include(FControlFlags,cfProcessingWMPaint);
try
Dispatch(TheMessage);
finally
Exclude(FControlFlags,cfProcessingWMPaint);
end;
end else
Dispatch(TheMessage); Dispatch(TheMessage);
end; end;

View File

@ -83,6 +83,8 @@ begin
if FControl = nil then if FControl = nil then
inherited CreateHandle inherited CreateHandle
else begin else begin
if ControlIsPainting then
debugln(['TControlCanvas.CreateHandle WARNING: accessing the canvas of '+DbgSName(FControl)+' is not supported outside of paint message']);
if FDeviceContext = 0 then if FDeviceContext = 0 then
begin begin
// store the handle locally since we need it to check (and dont // store the handle locally since we need it to check (and dont
@ -109,3 +111,8 @@ begin
FDeviceContext := 0; FDeviceContext := 0;
end; end;
end; end;
function TControlCanvas.ControlIsPainting: boolean;
begin
Result:=(FControl<>nil) and FControl.IsProcessingPaintMsg;
end;