Recent

Author Topic: Accessing canvas warning  (Read 6023 times)

timppl

  • Jr. Member
  • **
  • Posts: 80
Accessing canvas warning
« on: March 02, 2012, 09:00:44 am »
Hello all;
In the app I am porting from Delphi I get the following message continually in the output terminal

TControlCanvas.CreateHandle WARNING: accessing the canvas of TrackPlan:TTrackPlan is not supported outside of paint message

I don't understand what it means, as the code works fine and draws what it is supposed to, whereas the 'not supported' message implies that it should not work.
So, what exactly does this message mean?

Mandriva 2011, GTK2, Lazarus 35296

Regards

Tim
Mageia 8 Linux on x86

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Accessing canvas warning
« Reply #1 on: March 03, 2012, 12:54:01 pm »
That means that you're trying to paint on canvas out of paint event. It's bad technique and it works visually because gtk2 supports that. eg. qt/carbon/cocoa does not support painting outside of paint event.

timppl

  • Jr. Member
  • **
  • Posts: 80
Re: Accessing canvas warning
« Reply #2 on: March 05, 2012, 08:16:42 am »
Hi Zeljko

I suspected it was something like that. The code is as written for delphi and as it works on windows and linux/gtk2 refactoring goes to the bottom of the todo pile  :)

Regards

Tim
Mageia 8 Linux on x86

Thomas Munk

  • New member
  • *
  • Posts: 7
Re: Accessing canvas warning
« Reply #3 on: November 11, 2013, 11:06:16 am »
Wouldn't it be fair for LCL to check for TLCLCapability.lcCanDrawOutsideOnPaint before this DebugLn "WARNING: accessing the canvas of... is not supported outside of paint message"?


It might not (always) be best practice painting outside a paint event, but in some widgetsets it's not illegal.


Therefore, if used, the terminal should not be flooded with this message.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Accessing canvas warning
« Reply #4 on: November 14, 2013, 08:06:17 am »
Wouldn't it be fair for LCL to check for TLCLCapability.lcCanDrawOutsideOnPaint before this DebugLn "WARNING: accessing the canvas of... is not supported outside of paint message"?


It might not (always) be best practice painting outside a paint event, but in some widgetsets it's not illegal.


Therefore, if used, the terminal should not be flooded with this message.

Fixed in r43443.




Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Accessing canvas warning
« Reply #5 on: November 14, 2013, 08:38:34 am »
I disagree.
I like to be warned when creating code which will not work well on other architectures/OS-s/widgetsets.

If you really know why, there is nothing wrong when you use such techniques, but at least you should be warned.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Accessing canvas warning
« Reply #6 on: November 15, 2013, 08:41:59 am »
I disagree.
I like to be warned when creating code which will not work well on other architectures/OS-s/widgetsets.

If you really know why, there is nothing wrong when you use such techniques, but at least you should be warned.

You're right too , so now my question raises: should I revert that commit or better what to do ? :)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Accessing canvas warning
« Reply #7 on: November 15, 2013, 08:49:01 am »
I suppose the best of both worlds would be to make the Warning on by default, but add (yet another) compiling option that allows the developer to turn this particular Warning off if desired to write non-cross-platform or questionable code.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Accessing canvas warning
« Reply #8 on: November 15, 2013, 09:55:22 am »
Isn't there a turn of platform warnings (or something along those lines) directive? why don't you simple add the warning to platform group and let it be turned of when ever needed be.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thomas Munk

  • New member
  • *
  • Posts: 7
Re: Accessing canvas warning
« Reply #9 on: November 15, 2013, 01:50:42 pm »

I agree with howardpc:I think that a default warning is OK as long it can be turned off with a compiler directive - and maybe as taazz mentions: an existing directive?

Thomas Munk

  • New member
  • *
  • Posts: 7
Re: Accessing canvas warning
« Reply #10 on: November 15, 2013, 02:01:29 pm »
Maybe a little too quick: Normally LCL is precompiled and wouldn't react to a compiler directive, right?


In that case my vote is: Do not warn about something that IS legal on the current platform.

 

TinyPortal © 2005-2018