Recent

Author Topic: How do you make this go?  (Read 1622 times)

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: How do you make this go?
« Reply #30 on: August 10, 2020, 08:23:10 am »
Have you read the other post where handako has a working prototye of a clock.
I have now  :)

winni

  • Hero Member
  • *****
  • Posts: 1908
Re: How do you make this go?
« Reply #31 on: August 10, 2020, 12:09:59 pm »
Hi!

The whole mystery with the not working OnPaint for the Image1 is the crazy behaviour of the TImage with Lazarus:

You have to "initialize" it which is nowhere documented.

Solution 1: Put a background picture into image1 - like I did.
Solution 2: "initialize" image1 in the procedure FormCreate:

Code: Pascal  [Select][+][-]
  1. Image1.Canvas.Brush.color := clWhite;
  2. Image1.Canvas.Fillrect (Rect(0,0,Image1.width, Image1.Height));
  3.  
That is the whole secret.
And that lousy behaviour of the TImage should be documented somewhere. Since 20 years.

Winni

« Last Edit: August 10, 2020, 01:04:31 pm by winni »

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: How do you make this go?
« Reply #32 on: August 11, 2020, 12:30:17 am »
The whole mystery with the not working OnPaint for the Image1 is the crazy behaviour of the TImage with Lazarus:

You have to "initialize" it which is nowhere documented.
Yeah. I was unaware of that fact and was unable to find/locate that (small) piece of information. Now we know  :)

Thank you winni

lucamar

  • Hero Member
  • *****
  • Posts: 3084
Re: How do you make this go?
« Reply #33 on: August 11, 2020, 12:49:27 pm »
The whole mystery with the not working OnPaint for the Image1 is the crazy behaviour of the TImage with Lazarus [...]

It's not really crazy or a mistery. A TImage is basically a "presentation" control meant to show whatever is loaded into its Picture property while the proper control to draw something is TPaintBox.

Granted, one can make do with a TImage and its Canvas, but then one has to realize that if there is no Picture the Canvas is not "initialized". That's all there is to it. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 1908
Re: How do you make this go?
« Reply #34 on: August 11, 2020, 01:38:59 pm »
Hi lucamar!

But what if you just start to create a picture??
Then you got that trap where Tron and others stepped in.

There should be a createPicture or InitPicture for those cases.
But the initialization of the picture is completly hidden so it is not obvious when it is done!

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 3084
Re: How do you make this go?
« Reply #35 on: August 11, 2020, 02:05:32 pm »
But what if you just start to create a picture??

Then you use a TBitmap (or any other similar class) if you're doing it in code or use a TPaintBox if it's drawn by the user (like, say, in a "Paint" kind of program).

Painting in a TImage's canvas is really no better than painting in, say, a TPanel's canvas and it's, indeed, worse because at least the TPanel does have an initialized canvas while a TImage doesn't until either you load a Picture or initialize it yourself. And worse of all: as soon as you try almost any operation with picture (for example to save whatever you've just drawn) the TImage canvas is redrawn to synch with the Picture, so you lose whatever you draw there.

I'm not saying it can't be done and, indeed, there are lots of code snippets out there using that "solution"; I just think that taking all into account it's not reallya good idea unless one does know exactly what one's doing and, more important, why.

IMHO, of course ... ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018