Board index » delphi » How to turn screen updating on and off

How to turn screen updating on and off

Hello,

I've just started Delphi. I opened a database with lots of data. While the
database is opening I would like to turn off screen updating and then turn
it back on when finished. Something like this:

  ScreenUpdating := False;
try
  // open database here
finally
  ScreenUpdating := True;
end;

Is the correct statement Form1.Refresh?

Thank you

Yukiko

 

Re:How to turn screen updating on and off


There may be a better way within Delphi, but you
can do this through the Win API fairly easily.

At it's heart, it's a simple message to a window to
indicate if it should redraw or not.  There's some
additional logic that force a refresh when you're
turning redraw back on.

Here's a VB routine to outline the logic:

Public Sub g_form_set_redraw(ByVal oForm As Form, ByVal bRedraw As Boolean)
  Dim hWnd As Long
  Dim eRedraw As Long
  Dim iRet As Long
  Dim bSuccess As Boolean

  'set the redraw flag
  hWnd = oForm.hWnd
  iRet = SendMessage(hWnd, WM_SETREDRAW, CLng(bRedraw), 0&)
  bSuccess = (iRet = 0)

  'induce the window to redraw itself?
  If bSuccess And bRedraw Then
    'invalidation flags
    eRedraw = eRedraw Or RDW_INVALIDATE Or RDW_ERASE Or RDW_FRAME

    'RDW_ERASENOW is less aggressive than RDW_UPDATENOW
    eRedraw = eRedraw Or RDW_ERASENOW 'RDW_UPDATENOW

    'tell the kids
    eRedraw = eRedraw Or RDW_ALLCHILDREN

    iRet = RedrawWindow(hWnd, ByVal 0&, 0&, eRedraw)
  End If

  'return if the set worked
'  gb_form_set_redraw = bSuccess
End Sub

That junk with the ByVal 0& comes from the declaration of RedrawWindow
within VB--I'm just passing a null pointer.

Quote
"Yukiko Ishida" <y.ish...@clickout.co.uk> wrote in message

news:3b2bfc2e_2@dnews...
Quote
> Hello,

> I've just started Delphi. I opened a database with lots of data. While the
> database is opening I would like to turn off screen updating and then turn
> it back on when finished. Something like this:

>   ScreenUpdating := False;
> try
>   // open database here
> finally
>   ScreenUpdating := True;
> end;

> Is the correct statement Form1.Refresh?

> Thank you

> Yukiko

Re:How to turn screen updating on and off


Quote
In article <3b2bfc2e_2@dnews>, Yukiko Ishida wrote:
> I've just started Delphi. I opened a database with lots of data. While the
> database is opening I would like to turn off screen updating and then turn
> it back on when finished. Something like this:

>   ScreenUpdating := False;
> try
>   // open database here
> finally
>   ScreenUpdating := True;
> end;

You may want to look at TDataset.DisableControls and
TDataset.EnableControls.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:How to turn screen updating on and off


Hi again,

Thanks for the advice. My colleague had a related problem. He posted a
question on the delphi oleautomation group. Now mine works fine. Thank you.

His problem is that his application automates Word and when the automation
is over unless he puts a ShowMessage in the finally clause his apprication
stops responding. He put in the

SendMessage(frmMain.Handle, WM_SETREDRAW, WPARAM(True), 0)

suggested by Grinder but it still hasn't solved his problem. Any ideas?

Thanks Yuki

Re:How to turn screen updating on and off


Quote
> His problem is that his application automates Word and when the automation
> is over unless he puts a ShowMessage in the finally clause his apprication
> stops responding. He put in the

> SendMessage(frmMain.Handle, WM_SETREDRAW, WPARAM(True), 0)

> suggested by Grinder but it still hasn't solved his problem. Any ideas?

I don't see the connection between a non-responsive messagebox
and setting the window's redraw flag?

Indeed, using this by itself would have no effect--if the window's
redraw flag is already set.

Re:How to turn screen updating on and off


Hi,

Perhaps I didn't exprain properly. The window still fails to redraw itself
or locks. The only approach was to add a MessageBox. In Delphi ShowMessage.
This message box then forced the screen to redraw. Unfortunately this is not
a long-term approach.

Thanks Yuki

Quote
> I don't see the connection between a non-responsive messagebox
> and setting the window's redraw flag?

> Indeed, using this by itself would have no effect--if the window's
> redraw flag is already set.

Re:How to turn screen updating on and off


Quote
"Peter Below (TeamB)" wrote:

> In article <3b2bfc2e_2@dnews>, Yukiko Ishida wrote:
> > I've just started Delphi. I opened a database with lots of data. While the
> > database is opening I would like to turn off screen updating and then turn
> > it back on when finished. Something like this:

> You may want to look at TDataset.DisableControls and
> TDataset.EnableControls.

And be careful: calling DisableControls also disables the master/detail
relationship.
(see help).

AlexB

Re:How to turn screen updating on and off


This will sound stupid, but I also have some anomolies when i use wm_setredraw
messages, and the only way (sometimes)that I can get the window to start paiting
again is to do this:

   Form1.Visible:=False;
   Form1.Visible:=True;

Tell me what happens.

Davie

Quote
Yukiko Ishida wrote:
> Hi,

> Perhaps I didn't exprain properly. The window still fails to redraw itself
> or locks. The only approach was to add a MessageBox. In Delphi ShowMessage.
> This message box then forced the screen to redraw. Unfortunately this is not
> a long-term approach.

> Thanks Yuki

> > I don't see the connection between a non-responsive messagebox
> > and setting the window's redraw flag?

> > Indeed, using this by itself would have no effect--if the window's
> > redraw flag is already set.

Re:How to turn screen updating on and off


Have you tried the ScreenUpdating global mentioned by another
poster?  You may have better luck if you don't go behind Delphi's
back.

Quote
"Grinder" <no.s...@no.spam.spam.spam.net> wrote in message

news:3b2d46e5$1_1@dnews...
Quote
> > His problem is that his application automates Word and when the
automation
> > is over unless he puts a ShowMessage in the finally clause his
apprication
> > stops responding. He put in the

> > SendMessage(frmMain.Handle, WM_SETREDRAW, WPARAM(True), 0)

> > suggested by Grinder but it still hasn't solved his problem. Any ideas?

> I don't see the connection between a non-responsive messagebox
> and setting the window's redraw flag?

> Indeed, using this by itself would have no effect--if the window's
> redraw flag is already set.

Re:How to turn screen updating on and off


Hi Davie,

Added

try
  ...
finally
  ...
  frmMain.Visible := False;
  frmMain.Visible := True;
end;

to the finally clause. Thought the problem was solved until we changed the
combination of closing Word before setting the focus back on our
application. At which point the lock up or screen non-redraw happened.

Yuki

Quote
"Davie" <smatt...@smatters.com> wrote in message

news:3B2DFD2F.2CA2F144@smatters.com...
Quote
> This will sound stupid, but I also have some anomolies when i use
wm_setredraw
> messages, and the only way (sometimes)that I can get the window to start
paiting
> again is to do this:

>    Form1.Visible:=False;
>    Form1.Visible:=True;

> Tell me what happens.

Re:How to turn screen updating on and off


Hi All,

I wrote the code which fails to refresh the screen. It appears that the
fault is in the dll not the main application. I created a class to return
the result of the dll. That same class is declared in the main application.
But I didn't create the object before trying to use it. So, I've remove
references to the object. And now another problem appears. So far the screen
refresh problem has not surfaced again. Why the code in the dll runs fine
sometimes is still a mystery.

Thanks for your efforts and time everyone. Yuki solved her screen refresh
problem thanks to you.

Paul

Other Threads