Board index » cppbuilder » How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??


2004-05-11 12:17:03 AM
cppbuilder114
hi dear builders,
how can i show a ProgresBar for this function ?
/**********************************************/
void __fastcall TForm1::cmdUpperClick(TObject *Sender)
{
RichEdit1->Text = RichEdit1->Text.UpperCase();
}
/**********************************************/
i don't have a line that i can access, so i cannot set:
ProgressBar->Max = RichEdit1->Lines->Count;
is there another solution...?
thanks in advance...
Oren
 
 

Re:How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
how can i show a ProgresBar for this function ?
Using UpperCase(), you can't. You will just have to loop through the
characters 1 at a time manually using toupper() instead. For example:
#include <ctype.h>
void __fastcall TForm1::cmdUpperClick(TObject *Sender)
{
AnsiString s = RichEdit1->Text;
char *ptr = s.c_str();
ProgressBar1->Position = 0;
ProgressBar1->Max = s.Length();
ProgressBar1->StepBy = 1;
for(int x = 1; x <= s.Length(); ++x)
{
*(ptr++) = static_cast<char>(toupper(s[x]));
ProgressBar1->StepIt();
ProgressBar1->Update();
}
RichEdit1->Text = s;
}
Quote
i don't have a line that i can access, so i cannot set:

ProgressBar->Max = RichEdit1->Lines->Count;
If you want t go by lines instead of individual characters then do the
following:
void __fastcall TForm1::cmdUpperClick(TObject *Sender)
{
int count = RichEdit1->Lines->Count;
ProgressBar1->Position = 0;
ProgressBar1->Max = count;
ProgressBar1->StepBy = 1;
RichEdit1->Lines->BeginUpdate();
try
{
for(int x = 0; x < count; ++x)
{
RichEdit1->Lines->Strings[x] =
RichEdit1->Lines->Strings[x].UpperCase();
ProgressBar1->StepIt();
ProgressBar1->Update();
}
}
__finally {
RichEdit1->Lines->EndUpdate();
}
}
Gambit
 

Re:How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

hi Remy, i've took your second sample:
Quote
void __fastcall TForm1::cmdUpperClick(TObject *Sender)
{
int count = RichEdit1->Lines->Count;

ProgressBar1->Position = 0;
ProgressBar1->Max = count;
ProgressBar1->StepBy = 1;

RichEdit1->Lines->BeginUpdate();
try
{
for(int x = 0; x < count; ++x)
{
RichEdit1->Lines->Strings[x] =>
RichEdit1->Lines->Strings[x].UpperCase();
ProgressBar1->StepIt();
ProgressBar1->Update();
}
}
__finally {
RichEdit1->Lines->EndUpdate();
}
}
but i just wonder, WHY IS IT WORKS SOOOO SLOW ??
try it yourself..use this instead of your function:
Memo1->Text = Memo1->Text.UpperCase();
i guess it's get slow because you go line by line..
and my code take to whole text and makes it
uppercase at once..
hmm...is there maybe a possibility to optimize your function..?
Oren
 

{smallsort}

Re:How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
but i just wonder, WHY IS IT WORKS SOOOO SLOW ??
Probably due to all the GUI work that has been introduced. GUI operations
are slow in general.
Why do you want a progress bar on this anyway? Chances are, when you let
the code run without a progress bar at all, you will be able to convert
large amounts of text very fast so that the user wouldn't even see a change
in the progress bar to begin with.
Gambit
 

Re:How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im
Newsbeitrag news:40a00d18$ XXXX@XXXXX.COM ...
Quote

Why do you want a progress bar on this anyway? Chances are, when you let
the code run without a progress bar at all, you will be able to convert
large amounts of text very fast so that the user wouldn't even see a
change
in the progress bar to begin with.
well, it's true...OK you have to wait about 7 seconds for uppercasing
300 KByte of text..
the thing is our customer wants for every operation of the programm a
ProgressBar that shows where the programm is exactly at the moment..
i guess there is no optimizing solution for my
problem, right :-) ??
Oren
 

Re:How to show a ProgresBar for: RichEdit1->Text.UpperCase() ??

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
well, it's true...OK you have to wait about 7
seconds for uppercasing 300 KByte of text..
When I try the code you showed earlier, it takes <1 second (usually only
100-200 milliseconds) to upper-case 500KB of text. Something else in your
code has to be causing the delays
Gambit