Board index » delphi » Repeat Until Test (Not Working???)

Repeat Until Test (Not Working???)

Hi

  I'm a new programmer with delphi, I tried writing a simple repeat until
test to have a counter count to a number.  With the output to a label on
the screen.  The label doesn't update until the count is done.

How can I have the label automatically update as the count is increased.
Any help would be appreciated I have included the project I used as
test.zip

Please email me @ sle...@globalserve.net or post in this news group

Thank you
begin 600 test.zip
<encoded_portion_removed>
end

 

Re:Repeat Until Test (Not Working???)


Steve Learn <sle...@globalserve.net> wrote in article
<01bcb2ac$8cf7cb60$0a7f0b9a@{*word*104}empire>...

Quote
> Hi

>   I'm a new programmer with delphi, I tried writing a simple repeat until
> test to have a counter count to a number.  With the output to a label on
> the screen.  The label doesn't update until the count is done.

> How can I have the label automatically update as the count is increased.
> Any help would be appreciated I have included the project I used as
> test.zip

> Please email me @ sle...@globalserve.net or post in this news group

> Thank you

 repeat
    inc(counter);
    form1.label1.caption := inttostr(counter);
 //Here's what you need:
  application.processmessages;
  until (counter > 10000);

Re:Repeat Until Test (Not Working???)


On 27 Aug 1997 05:48:41 GMT, "Steve Learn" <sle...@globalserve.net>
wrote:

Quote
>  I'm a new programmer with delphi, I tried writing a simple repeat until
>test to have a counter count to a number.  With the output to a label on
>the screen.  The label doesn't update until the count is done.
>How can I have the label automatically update as the count is increased.
>Any help would be appreciated I have included the project I used as
>test.zip

First of all, I really doubt that it is a good idea to include your
entire project with your post. Next time, try only including the few
relevant lines of code.

As to your problem, try putting an Application.ProcessMessages
statment somewhere in the loop. This should do the trick for you.

Alan

Re:Repeat Until Test (Not Working???)


Steve Learn <sle...@globalserve.net> wrote in article
<01bcb2ac$8cf7cb60$0a7f0b9a@{*word*104}empire>...

Quote
>   I'm a new programmer with delphi, I tried writing a simple repeat until
> test to have a counter count to a number.  With the output to a label on
> the screen.  The label doesn't update until the count is done.

> How can I have the label automatically update as the count is increased.
> Any help would be appreciated I have included the project I used as
> test.zip

It will work in a DOS environment, but not Windows. Remember that Windows
uses an event driven architecture - you have to give your Windows a change
to process events (messages) from your application to 'update' (or paint)
your application's window. Simply adding a call to
Application.ProcessMessages in the loop should do the trick.

--from Delphi 3 Help File---
ProcessMessages interrupts the execution of an application so that Windows
can respond to events.
procedure ProcessMessages;
Description
Call ProcessMessages to permit Windows to process these events at the time
ProcessMessages is called. The ProcessMessages method cycles the Windows
message loop until it is empty and then returns control to the application.
Note
In Win32, neglecting message processing only the application calling
ProcessMessages, not other applications. In lengthy operations calling
ProcessMessages periodically will allow the application to respond to paint
and other messages.
--from Delphi 3 Help File---

regards,
Billy

Re:Repeat Until Test (Not Working???)


On 27 Aug 1997 05:48:41 GMT, "Steve Learn" <sle...@globalserve.net>
wrote:

Quote
>Hi

>  I'm a new programmer with delphi, I tried writing a simple repeat until
>test to have a counter count to a number.  With the output to a label on
>the screen.  The label doesn't update until the count is done.

>How can I have the label automatically update as the count is increased.
>Any help would be appreciated I have included the project I used as
>test.zip

You need to put an Application.ProcessMessages in the loop. The screen
doesn't get updated until the end of the function.

Re:Repeat Until Test (Not Working???)


On 27 Aug 1997, Thaddy wrote:

Quote

> Steve Learn <sle...@globalserve.net> wrote in article
> <01bcb2ac$8cf7cb60$0a7f0b9a@{*word*104}empire>...
> > Hi

> >   I'm a new programmer with delphi, I tried writing a simple repeat until
> > test to have a counter count to a number.  With the output to a label on
> > the screen.  The label doesn't update until the count is done.

> > How can I have the label automatically update as the count is increased.
> > Any help would be appreciated I have included the project I used as
> > test.zip

> > Please email me @ sle...@globalserve.net or post in this news group

> > Thank you

>  repeat
>     inc(counter);
>     form1.label1.caption := inttostr(counter);
>  //Here's what you need:
>   application.processmessages;
>   until (counter > 10000);

a label1.repaint would do the job too, wouldn't it?
experiment with the progressbar component

Re:Repeat Until Test (Not Working???)


Actually, you'd call the Refresh method if you wanted to restrict updates
(for performance reasons) to a particular form or control. Normally
Application.ProcessMessages is a better choice (in Windows 95) because it
allows Windows to continue to handle background tasks. This can be critical
of you somehow get yourself locked into an endless loop.

Elizabeth Wood <erw...@sover.net> wrote in article
<Pine.BSI.3.95.970829131626.10897A-100...@granite.sover.net>...

Quote

> On 27 Aug 1997, Thaddy wrote:

> >  repeat
> >     inc(counter);
> >     form1.label1.caption := inttostr(counter);
> >  //Here's what you need:
> >   application.processmessages;
> >   until (counter > 10000);

> a label1.repaint would do the job too, wouldn't it?
> experiment with the progressbar component

Other Threads