Board index » cppbuilder » (Deleting spaces,tabs and CRLF's in RichEdit) Programm freeze when there is no printable text..

(Deleting spaces,tabs and CRLF's in RichEdit) Programm freeze when there is no printable text..


2004-05-11 12:01:54 AM
cppbuilder42
hi dear builders,
i found a little bug in a function that deletes CRLF's and spaces around a
text
in a TRichEdit..
it fails (i mean my programm freezes) when there are ONLY CRLF's but NO
printable text / characters in the RichEdit..
what do i need to modify in my function to avoid it...?
thanks for any help...
Oren
/****************************************************/
void __fastcall TForm1::cmdTrimAllClick(TObject *Sender)
{
RichEdit1->Lines->BeginUpdate();
try
{
for(int x = RichEdit1->Lines->Count-1; x>= 0; --x)
{
AnsiString s = RichEdit1->Lines->Strings[x].Trim();
if(s.Length() == 0) {RichEdit1->Lines->Delete(x);}
else {break;}
}
bool test = true;
while(test)
{
AnsiString s = RichEdit1->Lines->Strings[0].Trim();
if(s.Length() == 0) {RichEdit1->Lines->Delete(0);}
else {test = false;}
}
for(int x = 0; x < Memo1->Lines->Count; x++)
{
RichEdit1->Lines->Strings[x] =
TrimLeft(RichEdit1->Lines->Strings[x]);
RichEdit1->Lines->Strings[x] =
TrimRight(RichEdit1->Lines->Strings[x]);
}
}
__finally
{
RichEdit1->Lines->EndUpdate();
}
}
 
 

Re:(Deleting spaces,tabs and CRLF's in RichEdit) Programm freeze when there is no printable text..

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
bool test = true;
while(test)
You need to test the RichEdit's Count instead. If your while() loop, or the
previous for() loop, happens to clear the RichEdit, you're not checking that
so you can exit your loop.
Quote
for(int x = 0; x < Memo1->Lines->Count; x++)
Why are you using a Memo's count instead of the RichEdit's count?
Use this code instead:
void __fastcall TForm1::cmdTrimAllClick(TObject *Sender)
{
RichEdit1->Lines->BeginUpdate();
try
{
for(int x = RichEdit1->Lines->Count-1; x>= 0; --x)
{
AnsiString s = RichEdit1->Lines->Strings[x].Trim();
if( s.Length() == 0 )
RichEdit1->Lines->Delete(x);
else
break;
}
while( RichEdit1->Lines->Count>0 )
{
AnsiString s = RichEdit1->Lines->Strings[0].Trim();
if( s.Length() == 0 )
RichEdit1->Lines->Delete(0);
else
break;
}
for(int x = 0; x < RichEdit1->Lines->Count; ++x)
RichEdit1->Lines->Strings[x] =
RichEdit1->Lines->Strings[x].Trim();
}
__finally {
RichEdit1->Lines->EndUpdate();
}
}
Gambit
 

Re:(Deleting spaces,tabs and CRLF's in RichEdit) Programm freeze when there is no printable text..

thanks Remy ! works perfect :-)
Oren
 

{smallsort}