Solved

prevent screen-flickering? HOW?

Posted on 1997-08-18
10
1,457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

697 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