Solved

prevent screen-flickering? HOW?

Posted on 1997-08-18
10
1,445 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 92
add combobox item based on numbers 9 154
How to renew a Delphi rad-studio licence? 5 69
Delphi: sending SMS on android platform 1 34
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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