Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Stream Output.

C.FeverC.Fever Member Posts: 2
Sorry, I don't really know how to word what I'm wanting.

Ok, here's what I'm trying to do.

I have a button and when you click it, a loop starts that cycles from 0 to 1000.
Now, through each number, I have it output that number to a label on the form.
But, it doesn't output in real time, rather only the last number.

I'm guessing because when the click is pressed, it executes the code and puts it in a buffer til it's finished processing, then outputs.
I want it to output to the form without waiting til it's finished.
If I'm doing it the wrong way, plz show me how to do what I'm trying to achieve...


[code]void __fastcall TForm1::btnGoClick(TObject *Sender)
{
int n = 0;
do
{
lblTest->Caption = IntToStr(n);
n++;
} while (n < 100000);
}[/code]


Thank you very much.
Any help or pointers is appreciated.

Comments

  • zibadianzibadian Member Posts: 6,349
    : Sorry, I don't really know how to word what I'm wanting.
    :
    : Ok, here's what I'm trying to do.
    :
    : I have a button and when you click it, a loop starts that cycles
    : from 0 to 1000.
    : Now, through each number, I have it output that number to a label on
    : the form.
    : But, it doesn't output in real time, rather only the last number.
    :
    : I'm guessing because when the click is pressed, it executes the code
    : and puts it in a buffer til it's finished processing, then outputs.
    : I want it to output to the form without waiting til it's finished.
    : If I'm doing it the wrong way, plz show me how to do what I'm trying
    : to achieve...
    :
    :
    : [code]: void __fastcall TForm1::btnGoClick(TObject *Sender)
    : {
    : int n = 0;
    : do
    : {
    : lblTest->Caption = IntToStr(n);
    : n++;
    : } while (n < 100000);
    : }[/code]:
    :
    :
    : Thank you very much.
    : Any help or pointers is appreciated.
    :
    The problem isn't the outputting; that's happening correctly. The problem is that windows doesn't refresh the screen to show the output.
    Screens are refreshed when windows sends a message to the program to refresh it. Your code doesn't take the time to listen to those messages, thus doesn't update the screen.
    Solution: process the windows messages within the loop. I don't know the correct procedure name (In Delphi it was call ProcessMessages()), but that should show the numbers.
  • C.FeverC.Fever Member Posts: 2
    : : Sorry, I don't really know how to word what I'm wanting.
    : :
    : : Ok, here's what I'm trying to do.
    : :
    : : I have a button and when you click it, a loop starts that cycles
    : : from 0 to 1000.
    : : Now, through each number, I have it output that number to a label on
    : : the form.
    : : But, it doesn't output in real time, rather only the last number.
    : :
    : : I'm guessing because when the click is pressed, it executes the code
    : : and puts it in a buffer til it's finished processing, then outputs.
    : : I want it to output to the form without waiting til it's finished.
    : : If I'm doing it the wrong way, plz show me how to do what I'm trying
    : : to achieve...
    : :
    : :
    : : [code]: : void __fastcall TForm1::btnGoClick(TObject *Sender)
    : : {
    : : int n = 0;
    : : do
    : : {
    : : lblTest->Caption = IntToStr(n);
    : : n++;
    : : } while (n < 100000);
    : : }[/code]: :
    : :
    : :
    : : Thank you very much.
    : : Any help or pointers is appreciated.
    : :
    : The problem isn't the outputting; that's happening correctly. The
    : problem is that windows doesn't refresh the screen to show the
    : output.
    : Screens are refreshed when windows sends a message to the program to
    : refresh it. Your code doesn't take the time to listen to those
    : messages, thus doesn't update the screen.
    : Solution: process the windows messages within the loop. I don't know
    : the correct procedure name (In Delphi it was call
    : ProcessMessages()), but that should show the numbers.

    Just want to say thank you, I suppose I was just thinking too hard.
    Just added [code]Application->ProcessMessages();[/code] in the loop and it worked flawlessly. :)
Sign In or Register to comment.