Solved

prevent screen-flickering? HOW?

Posted on 1997-08-18
10
1,439 Views
Last Modified: 2012-05-04
I would like to prevent the user from seeing the screen updating itself:

I have 1 mainform (Main) en let's say 2 'child'forms (it's not an MDI app).
The 2 'child'forms contain a lot of controls (24 editboxes, 30 labels, 1 listbox, 1 combobox, several buttons, 9 checkboxes, 9 spinedits, 3 groupboxes).
On my mainform there is are two buttons (one for each 'child'-form). When you press the button for 'child'form1 'child'form1 is created within the mainform.

PROBLEM:
~~~~~~~

When I switch between the two 'child' forms (via the buttons) you can see the controls being painted:
first the white boxes, then the lines and text.
How do I prevent this? I want the screen to popup at once when all the drawing is finished.

On the ATARI (years ago!) I let everything being painted on an offscreen bitmap. After all the painting was done I copied the bitmap to the screen...!

How do I do this in Delphi? How are the events working (onpaint, WMPAINT)?
createcompatibleBitmap/createCompatibleDC?

Thanx a million for your reaction!
0
Comment
Question by:ozeegers
  • 7
  • 3
10 Comments
 
LVL 2

Accepted Solution

by:
icampbe1 earned 200 total points
ID: 1341709
There is a first time rendering on the component's canvas that occurs for each control on the form.  This is what you are observing.  If you don't have to destroy and re-create the other two forms each time, that will work a lot better.  That is, you can use 'Form.Hide' and 'Form.Show' when you switch between them instead of completely destroying them and re-creating them.  Is it necessary to destroy them?

Painting can be controlled by overriding the controls 'paint' method.  This is called every time the control must repaint itself.  You might find this cleaner than grabbing the WM_PAINT message but it really doesn't matter which.

Some of the initial paint delay that you observe is the 'reading' of the control's published properties (like the text of an edit box or the caption of a label).  If you have a large and busy form like you do, the form will render more quickly with 'empty' controls.  If this is managable, you might try that and then fill them in as needed (or some combination of both).

I hope this helps,
Ian C.
0
 

Author Comment

by:ozeegers
ID: 1341710
Thank you for your quick answer.
I'm not so sure if it helps me any further. I'm not an expert in Delphi so..........
I am destroying my forms in order to keep resource consumption low (the user is able to choose between 30 forms to add to his list; the average user will add 10 forms to the list, so 10 forms with lots of control on is will consume very much resources?).
Could you please write a complete example on how I let windows draw the form on an offscreen bitmap (in memory) first and then copy the bitmap to the screen? I think that will solve the problem because it's not that slow but it's the building up of the control that one can see that is annoying....

Thank you very much in advance,

O.Zeegers
0
 

Author Comment

by:ozeegers
ID: 1341711
Thank you for your quick answer.
I'm not so sure if it helps me any further. I'm not an expert in Delphi so..........
I am destroying my forms in order to keep resource consumption low (the user is able to choose between 30 forms to add to his list; the average user will add 10 forms to the list, so 10 forms with lots of control on is will consume very much resources?).
Could you please write a complete example on how I let windows draw the form on an offscreen bitmap (in memory) first and then copy the bitmap to the screen? I think that will solve the problem because it's not that slow but it's the building up of the control that one can see that is annoying....

Thank you very much in advance,

O.Zeegers

BTW. What does the field 'incease point to' mean?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 2

Expert Comment

by:icampbe1
ID: 1341712
The resources used by controls and forms is surprisingly low.  If you want to do a small test, just display the 'InstanceSize' of any object and I'm sure you'll be surprised.  I know when you look at something like a form, it seems big, but you have to remember that it is 'drawn', not a bitmap.

Try:   ShowMessage( IntToStr( Edit1.InstanceSize) );

Or any other object for that matter.  InstanceSize is declared in TObject, so you can use it on any object anywhere, as long as it has been instantiated (who makes up these words?).

With this in mind, you may re-think your ideas about keeping these forms created and ready to go.  It isn't the burden you might think.

Oh yeah, 'increase points to' is used to increase to points that you are offering for a solution in an effort to get someones attention.  Theoretically, the more you offer, the more likely you will have a question answered.  Not at all like the spirit of Christmas.

Cheers,
Ian C.

BTW.  Thanks for the points.
0
 

Author Comment

by:ozeegers
ID: 1341713
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341714
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341715
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341716
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341717
>Could you please write a complete example on how I let
>windows draw the form on an offscreen bitmap (in memory)
>first and then copy the bitmap to the screen?


please check the source on any errors!
Thanx!
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1341718
Now I see, you stutter....

I know what you're asking for, but that's not how windows does it.  Windows sends a a WM_PAINT message to any control that must paint or draw itself because it must be rendered on the screen.  It isn't your choice per se.  You don't pre-draw, like on a bitmap, and then show it.  Every control on your form is responsible for painting itself as well, and Windows tells it when to do so.

A good portion of the delay you are seeing is the from the PROPERTIES like the lablel.caption and editbox.text being filled in after the constructor has run.   You'll notice that this delay is mostly the 'first time'.

If the main form is the one that's the most annoying, then you can try Application.ShowMainForm := FALSE;  until you are ready to show it, but at least it's ready to go.

I wasn't being evasive when I didn't give you an example of what we did in the old days.  It's just not the same.

Hope this helps a bit more,

Ian C.

0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question