Board index » delphi » Problem with Repaint

Problem with Repaint

Quote
"Peter Lawrance" <p...@seol.net.au> wrote in message

news:KKoN4.3$Nx6.658@vic.nntp.telstra.net...

Quote
> I have several places in an application where I display an information box
> and a progress bar. In some places I have no problem, while in other
places
> the screen image retains the gap where the previous dialog box was and
won't
> repaint and display the new elements. No matter what I do or how I order
the
> lines of code, it goes all the way through the loop that the progress bar
> relates to before repainting. Can anyone see a reason for this in the code
> below. BTW, it makes no difference whether I include DisableControls or
not,
> or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint.
Also,
> note that functions like AppendFrom() are from the Topaz library.

Try adding Application.ProcessMessages at various appropriate points in the
code. This allows your application to respond to its message queue.
 

Re:Problem with Repaint


You need to add Application.ProcessMessages to your loops.

Paul / ColumbuSoft
www.columbusoft.com

Quote
Peter Lawrance <p...@seol.net.au> wrote in message

news:KKoN4.3$Nx6.658@vic.nntp.telstra.net...
Quote
> I have several places in an application where I display an information box
> and a progress bar. In some places I have no problem, while in other
places
> the screen image retains the gap where the previous dialog box was and
won't
> repaint and display the new elements. No matter what I do or how I order
the
> lines of code, it goes all the way through the loop that the progress bar
> relates to before repainting. Can anyone see a reason for this in the code
> below. BTW, it makes no difference whether I include DisableControls or
not,
> or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint.
Also,
> note that functions like AppendFrom() are from the Topaz library.

> ---------------------code begins---------------------

>   IF ImportDialog.Execute then
>     begin

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 prepares the file...';
>       Form1.PleaseWait2.Visible := TRUE;
>       Form1.PleaseWait2.Repaint;

>       GSTocktake.DisableControls;
>       GSTocktake.SetOrderTo(0);
>       GSTocktake.AppendFrom(ImportDialog.FileName);
>       GSTocktake.Reindex;
>       GSTocktake.GoTop;

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 calculates totals...';
>       Form1.PleaseWait2.Repaint;
>       Form1.ProgressBar1.Min := 0;
>       Form1.ProgressBar1.Max := GSTocktake.RecCount;
>       Form1.ProgressBar1.Position := 0;
>       Form1.ProgressBar1.Visible := TRUE;
>       Form1.Repaint;

>       While not Form1.GSTocktake.dEOF do
>         begin
>         CalculateGrandTotals(GSTocktake);
>         ProgressBar1.StepIt;
>         GSTocktake.Skip(1);
>         end;

>       GSTocktake.SetOrderTo(2);
>       GSTocktake.GoTop;
>       If GSTocktake.RecCount > 0 Then GSTocktake.DeleteRec;
>       GSTocktake.EnableControls;
>       CalculateTotals(GSTocktake,FALSE);
>       PleaseWait2.Hide;
>       ProgressBar1.Hide;
>       ActiveControl := TzGrid1;

> ---------------------code ends-----------------------

Re:Problem with Repaint


I have several places in an application where I display an information box
and a progress bar. In some places I have no problem, while in other places
the screen image retains the gap where the previous dialog box was and won't
repaint and display the new elements. No matter what I do or how I order the
lines of code, it goes all the way through the loop that the progress bar
relates to before repainting. Can anyone see a reason for this in the code
below. BTW, it makes no difference whether I include DisableControls or not,
or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint. Also,
note that functions like AppendFrom() are from the Topaz library.

---------------------code begins---------------------

  IF ImportDialog.Execute then
    begin

      Form1.PleaseWait2.Caption :=
        'Please wait while GSTocktake 2000 prepares the file...';
      Form1.PleaseWait2.Visible := TRUE;
      Form1.PleaseWait2.Repaint;

      GSTocktake.DisableControls;
      GSTocktake.SetOrderTo(0);
      GSTocktake.AppendFrom(ImportDialog.FileName);
      GSTocktake.Reindex;
      GSTocktake.GoTop;

      Form1.PleaseWait2.Caption :=
        'Please wait while GSTocktake 2000 calculates totals...';
      Form1.PleaseWait2.Repaint;
      Form1.ProgressBar1.Min := 0;
      Form1.ProgressBar1.Max := GSTocktake.RecCount;
      Form1.ProgressBar1.Position := 0;
      Form1.ProgressBar1.Visible := TRUE;
      Form1.Repaint;

      While not Form1.GSTocktake.dEOF do
        begin
        CalculateGrandTotals(GSTocktake);
        ProgressBar1.StepIt;
        GSTocktake.Skip(1);
        end;

      GSTocktake.SetOrderTo(2);
      GSTocktake.GoTop;
      If GSTocktake.RecCount > 0 Then GSTocktake.DeleteRec;
      GSTocktake.EnableControls;
      CalculateTotals(GSTocktake,FALSE);
      PleaseWait2.Hide;
      ProgressBar1.Hide;
      ActiveControl := TzGrid1;

---------------------code ends-----------------------

Re:Problem with Repaint


Have you tried using Application.processmessages in stead of repaint
this might refresh the process.
Steve.

       Form1.PleaseWait2.Caption :=
         'Please wait while GSTocktake 2000 prepares the file...';
       Form1.PleaseWait2.Visible := TRUE;
       Application.processmessages;

       GSTocktake.DisableControls;
       GSTocktake.SetOrderTo(0);
       GSTocktake.AppendFrom(ImportDialog.FileName);
       GSTocktake.Reindex;
       GSTocktake.GoTop;

       Form1.PleaseWait2.Caption :=
         'Please wait while GSTocktake 2000 calculates totals...';
       Application.processmessages;
       Form1.ProgressBar1.Min := 0;
       Form1.ProgressBar1.Max := GSTocktake.RecCount;
       Form1.ProgressBar1.Position := 0;
       Form1.ProgressBar1.Visible := TRUE;
       Application.processmessages;

       While not Form1.GSTocktake.dEOF do
         begin
         CalculateGrandTotals(GSTocktake);
         ProgressBar1.StepIt;
        Application.processmessages;
         GSTocktake.Skip(1);
         end;

       GSTocktake.SetOrderTo(2);
       GSTocktake.GoTop;
       If GSTocktake.RecCount > 0 Then GSTocktake.DeleteRec;
       GSTocktake.EnableControls;
       CalculateTotals(GSTocktake,FALSE);
       Application.processmessages;
       PleaseWait2.Hide;
       ProgressBar1.Hide;
       ActiveControl := TzGrid1;

 ---------------------code ends-----------------------

Quote
Peter Lawrance <p...@seol.net.au> wrote in message

news:KKoN4.3$Nx6.658@vic.nntp.telstra.net...
Quote
> I have several places in an application where I display an information box
> and a progress bar. In some places I have no problem, while in other
places
> the screen image retains the gap where the previous dialog box was and
won't
> repaint and display the new elements. No matter what I do or how I order
the
> lines of code, it goes all the way through the loop that the progress bar
> relates to before repainting. Can anyone see a reason for this in the code
> below. BTW, it makes no difference whether I include DisableControls or
not,
> or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint.
Also,
> note that functions like AppendFrom() are from the Topaz library.

> ---------------------code begins---------------------

>   IF ImportDialog.Execute then
>     begin

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 prepares the file...';
>       Form1.PleaseWait2.Visible := TRUE;
>       Form1.PleaseWait2.Repaint;

>       GSTocktake.DisableControls;
>       GSTocktake.SetOrderTo(0);
>       GSTocktake.AppendFrom(ImportDialog.FileName);
>       GSTocktake.Reindex;
>       GSTocktake.GoTop;

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 calculates totals...';
>       Form1.PleaseWait2.Repaint;
>       Form1.ProgressBar1.Min := 0;
>       Form1.ProgressBar1.Max := GSTocktake.RecCount;
>       Form1.ProgressBar1.Position := 0;
>       Form1.ProgressBar1.Visible := TRUE;
>       Form1.Repaint;

>       While not Form1.GSTocktake.dEOF do
>         begin
>         CalculateGrandTotals(GSTocktake);
>         ProgressBar1.StepIt;
>         GSTocktake.Skip(1);
>         end;

>       GSTocktake.SetOrderTo(2);
>       GSTocktake.GoTop;
>       If GSTocktake.RecCount > 0 Then GSTocktake.DeleteRec;
>       GSTocktake.EnableControls;
>       CalculateTotals(GSTocktake,FALSE);
>       PleaseWait2.Hide;
>       ProgressBar1.Hide;
>       ActiveControl := TzGrid1;

> ---------------------code ends-----------------------

Re:Problem with Repaint


Like all other answers suggest you can use Application.ProcessMessages, but
it has some {*word*193} side effects (like if you press a button the OnClick will
execute during the ProcessMessages !).

A better way to force painting is to call the Update method of the form.

"Peter Lawrance" <p...@seol.net.au> schreef in bericht
news:KKoN4.3$Nx6.658@vic.nntp.telstra.net...

Quote
> I have several places in an application where I display an information box
> and a progress bar. In some places I have no problem, while in other
places
> the screen image retains the gap where the previous dialog box was and
won't
> repaint and display the new elements. No matter what I do or how I order
the
> lines of code, it goes all the way through the loop that the progress bar
> relates to before repainting. Can anyone see a reason for this in the code
> below. BTW, it makes no difference whether I include DisableControls or
not,
> or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint.
Also,
> note that functions like AppendFrom() are from the Topaz library.

> ---------------------code begins---------------------

>   IF ImportDialog.Execute then
>     begin

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 prepares the file...';
>       Form1.PleaseWait2.Visible := TRUE;
>       Form1.PleaseWait2.Repaint;

>       GSTocktake.DisableControls;
>       GSTocktake.SetOrderTo(0);
>       GSTocktake.AppendFrom(ImportDialog.FileName);
>       GSTocktake.Reindex;
>       GSTocktake.GoTop;

>       Form1.PleaseWait2.Caption :=
>         'Please wait while GSTocktake 2000 calculates totals...';
>       Form1.PleaseWait2.Repaint;
>       Form1.ProgressBar1.Min := 0;
>       Form1.ProgressBar1.Max := GSTocktake.RecCount;
>       Form1.ProgressBar1.Position := 0;
>       Form1.ProgressBar1.Visible := TRUE;
>       Form1.Repaint;

>       While not Form1.GSTocktake.dEOF do
>         begin
>         CalculateGrandTotals(GSTocktake);
>         ProgressBar1.StepIt;
>         GSTocktake.Skip(1);
>         end;

>       GSTocktake.SetOrderTo(2);
>       GSTocktake.GoTop;
>       If GSTocktake.RecCount > 0 Then GSTocktake.DeleteRec;
>       GSTocktake.EnableControls;
>       CalculateTotals(GSTocktake,FALSE);
>       PleaseWait2.Hide;
>       ProgressBar1.Hide;
>       ActiveControl := TzGrid1;

> ---------------------code ends-----------------------

Re:Problem with Repaint


Try Application.ProcessMessages (in the loop). It might help.

Jasper D.

On Wed, 26 Apr 2000 07:43:55 +0930, "Peter Lawrance" <p...@seol.net.au>
wrote:

Quote
>I have several places in an application where I display an information box
>and a progress bar. In some places I have no problem, while in other places
>the screen image retains the gap where the previous dialog box was and won't
>repaint and display the new elements. No matter what I do or how I order the
>lines of code, it goes all the way through the loop that the progress bar
>relates to before repainting. Can anyone see a reason for this in the code
>below. BTW, it makes no difference whether I include DisableControls or not,
>or whether I say Repaint, Form1.Repaint or Form1.PleaseWait2.Repaint. Also,
>note that functions like AppendFrom() are from the Topaz library.

Re:Problem with Repaint


In article <KKoN4.3$Nx6....@vic.nntp.telstra.net>, p...@seol.net.au
says...

Quote
> I have several places in an application where I display an information box
> and a progress bar. In some places I have no problem, while in other places
> the screen image retains the gap where the previous dialog box was and won't
> repaint and display the new elements. No matter what I do or how I order the
> lines of code, it goes all the way through the loop that the progress bar

Try invalidate method.

Also, if you are using some tiem consumpting loop, make sure you put
within it call to Application.ProcessMEssages to leave some time space
for Windows to maintain messages.

Pedja

Other Threads