DelphiFAQ Home Search:

Msg 'Canvas does not allow drawing'

 

comments13 comments. Current rating: 4 stars (4 votes). Leave comments and/ or rate it.

Question:

What does the error message 'Canvas does not allow drawing' mean?

Answer:

  1. you may have run out of resources, which means a new DC cannot be allocated. Usually this is a result of not freeing unused DCs or other objects.
  2. you are attempting to draw to an device context that is not yet valid. Such as in the create constructor of a component.
  3. you are trying to draw on a canvas while your last draw-operation has not finished yet. In this case you can use Canvas.Lock() or Canvas.TryLock() to fix it.


Comments:

2006-03-16, 03:46:40
anonymous from Taiwan  
rating
Thanks
2006-06-08, 00:39:51
anonymous from United States  
To be honest, I'm not sure what it means, however, I feel that it may mean that a particular site does not want you downloading their images.
2006-11-29, 22:29:16
fuqiao from China  
This Happens when you continuely Create a kind of Form dynamicly,You may Add some Delay among the Creations.
2007-02-26, 19:01:05
donotsendmeanyspamokmyemailaddressisatheistgeek@gmail.com from New Zealand  
rating
This issue happened to me when I was trying to use ShowMessage inside a thread's Execute method. It didn't happen when I stepped through the code, only when running it without breakpoints. Odd. I guess the ShowMessage function is not thread safe, or something.
2007-03-18, 15:40:36
spotsy05@comcast.net from Richmond in Virginia, United States  
rating
i need to know what DC stands for because i get thie error message saying canvas does not allow drawing and i cant figure out why it keeps doing this and it freezing up on me. and i dont know whats going on. i just like to know how to get rid of it
2007-03-21, 09:36:02
anonymous from Brazil  
rating
The problem is on GetAveCharSize function, you need to change line 128 of dialogs.pas from
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
to:
If IsMultiThread Then
Canvas.Lock;
Try
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Finally
If IsMultiThread Then
Canvas.Unlock;
End;

After this change, showmessage, inputbox and messagedlg become 'BeginThread' friendly... (Since BeginThread sets IsMultiThread to true...)
I do some test into running activescript in a thread, and get this canvas errors often with all boxes from dialogs, i test with my own copy of dialogs (called messageboxes) and the errors still occurred.
After this change, i test and do not see the canvas errors again. (yes, I DIG deeply into VCL to find... lol... 'CreateHandle' of TControlCanvas try to 'free' some handles when the internal list becomes full... if can 'lock' it... sometimes... he free ITSELF... causing null handle and this errors... only on multithread applications... off course...
2007-04-11, 02:36:11
[hidden] from Netherlands  
At my system this occered when ASUS probe was running. After deleting ASUS probe no problems anymore.
2007-06-24, 17:06:36   (updated: 2007-06-24, 17:07:42)
gobears_78@hotmail.com from Netherlands  
Hi, today I purchased Digital Picture Recovery to recover digital picture that have been lost o my computer. After scanning my hard-drive you have to select which picture you want to recover, but then disaster strikes: I get the message: Canvas doe not allow drawing.
Dos anyone knows what the problem is and what can be done about it??
2007-07-04, 03:22:52
[hidden] from United Kingdom  
i am trying to run few things in my thread which initiate a form object , so i am getting the error in the Create line of my code.
I could not figure out where to place the TryLock/Lock . so can you help me in this regard.
2008-02-08, 04:38:29   (updated: 2008-02-08, 04:39:56)
ageu from Brasília, Brazil  

Ativar a propriedade

panel: TPanel

panel.DoubleBuffered := True;
2008-02-18, 19:44:18
anonymous from United States  
I found that if you turn off Asus Prob, the Msg 'Canvas does not allow drawing' will stop.
2008-05-07, 10:47:37
anonymous from Brazil  
amigos tem um programa que da esse erro canvas does not allon drawing, so que no windows 98 ele roda normal quando passo para o windows xp, e que da esse erro, como faço para corrigi esse erro.
2008-09-07, 06:47:20
sMallcar from Taiwan  
I just fix My problem with 'Canvas does not allow',

that's because I draw the canvas in event Timer,

I just add Canvas.lock at the Timer begin
and Canvas.unlokc at the Timer end.

like this
-------------
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
if not DXDraw1.CanDraw then exit;

DXDraw1.Surface.Canvas.Lock;
.
.
DXDraw1.Surface.Canvas.UnLock;
end;
-----------------

it's works. Hope this message CAN HELP some guys who got the same problem with me

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.