Board index » cppbuilder » TStaticText flickle when updated in a loop

TStaticText flickle when updated in a loop


2005-08-24 05:22:03 PM
cppbuilder7
I have a for loop like this:
for(int i=0; i<RecordCount; i++)
{
//do some query on a batabase, base on a list with RecordCount number of
item
//Fill in a TStringGrid with tthe result of the query
StaticText1->Caption = IntToStr(i+1) + "/" + IntToStr(RecordCount);
//call Next() for the database
}
the problem is, while processing the loop, the StaticText keeps flashing,
making it impossible see the text (in this case it's a progress indicator) -
Actually, I couldn't see the text at all if not paid close attention, which
initially lead me to believe the StaticText is totally invisible... I tried
the same setting with a TLabel, it's totally invisible while in the loop,
not even a brief flashing of the text at all.
Is there anyway to make the text show steadily? The loop isn't short, it
contains about 1600 items (loops) and the whole process tooks about 2
minutes to complete.
Thanks in advance.
 
 

Re:TStaticText flickle when updated in a loop

Choykw wrote:
Quote
I have a for loop like this:

for(int i=0; i<RecordCount; i++)
{
//do some query on a batabase, base on a list with RecordCount number of
item
//Fill in a TStringGrid with tthe result of the query
StaticText1->Caption = IntToStr(i+1) + "/" + IntToStr(RecordCount);
//call Next() for the database
}

the problem is, while processing the loop, the StaticText keeps flashing,
making it impossible see the text (in this case it's a progress indicator) -
Actually, I couldn't see the text at all if not paid close attention, which
initially lead me to believe the StaticText is totally invisible... I tried
the same setting with a TLabel, it's totally invisible while in the loop,
not even a brief flashing of the text at all.

Is there anyway to make the text show steadily? The loop isn't short, it
contains about 1600 items (loops) and the whole process tooks about 2
minutes to complete.

Thanks in advance.


Try to update the label every n items, for example:
if ((i & 15) == 0)
StaticText1->Caption = IntToStr(i+1) + "/" + IntToStr(RecordCount);
You may need also to update on the last item
if (((i & 15) == 0) || (i == RecordCount-1))
StaticText1->Caption = IntToStr(i+1) + "/" + IntToStr(RecordCount);
--
Regards
Miguel Gimenez
 

Re:TStaticText flickle when updated in a loop

"Choykw" < XXXX@XXXXX.COM >wrote:
Quote

[...] the same setting with a TLabel, it's totally invisible
while in the loop,
I would suggest the same as Miguel in as much that you not try
to update the Label every itteration of the loop. One percent
is more than enough information on the progress. However, you
also need to call Update when you change the Labels' Caption
if you want it visible to the user before you change it again.
~ JD
 

{smallsort}