Board index » cppbuilder » Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...


2004-03-01 06:13:53 AM
cppbuilder22
hi dear builders,
I found a strange bug in my application...
I'm setting the length of each Line in RichEdit to (for example) "6"
heres what I have:
_________________________________
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
OK, now here is the result:
________________________________
text t
text t
text t
my function works for short text,but when I load a textfile
with about 30 KByte, I need to call the function several times,
or with other words (the user has to press the button several times)
until I get the result that I need like above...why..?
Is something went wrong with the for( ) loop:
for(int x = 0; x < p->Lines->Count; ++x)
can someone help..?
Oren
/*************************************************************/
void SetLinesLength(TRichEdit* p, int length)
{
Screen->Cursor = crHourGlass;
try
{
p->Lines->BeginUpdate();
for(int x = 0; x < p->Lines->Count; ++x)
if(p->Lines->Strings[x].Length()>length)
{
if(p->Lines->Strings[x][p->Lines->Strings[x].Length()] != '\r\n' )
{
p->Lines->Strings[x] = p->Lines->Strings[x].SetLength(length);
Application->ProcessMessages();
}
else
{
p->Lines->Strings[x] = p->Lines->Strings[x].SetLength(length);
Application->ProcessMessages();
}
}
}
__finally
{
p->Lines->EndUpdate();
Screen->Cursor = crDefault;
}
}
void __fastcall TfrmTextlaenge_setzen::Button1Click(TObject *Sender)
{
int i = StrToInt(Edit1->Text);
SetLinesLength(Form2->RichEdit1, i);
}
 
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

Oren Halvani wrote:
Quote
my function works for short text,but when I load a textfile
with about 30 KByte, I need to call the function several times,
The cause is not a large file but long lines and WordWrap true.
That code will not work for WordWrap true.
Hans.
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
if(p->Lines->Strings[x][p->Lines->Strings[x].Length()] !=
'\r\n' )
That is not a valid operation, and in fact should not even compile in the
first place.
First, the lines obtained from Lines->Strings[] will *never* include "\r\n"
at all, thus the test would always fail.
Second, you are trying to specify two characters between single quotes,
which you cannot do. You can only specify a single character.
Third, the [] operator returns a single character, thus you are trying to
compare a single character to a dual-character sequence, which will always
fail even if the code syntax you are using were acceptable by the compiler
(which it is not).
Why are you even using an if() statement for testing the line ending anyway?
You are performing the exact same code in both blocks of code regardless of
the results of the if() statement. Thus, you can get rid of the if()
statement altogether:
void SetLinesLength(TRichEdit* p, int length)
{
Screen->Cursor = crHourGlass;
try
{
p->Lines->BeginUpdate();
try
{
for(int x = 0; x < p->Lines->Count; ++x)
{
AnsiString s = p->Lines->Strings[x];
if( s.Length()>length )
p->Lines->Strings[x] = s.SetLength(length);
}
}
__finally {
p->Lines->EndUpdate();
}
}
__finally {
Screen->Cursor = crDefault;
}
}
Gambit
 

{smallsort}

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

Remy Lebeau (TeamB) wrote:
Quote
That is not a valid operation, and in fact should not even compile in the
first place.
Then blame bcb3.
Quote
.. Thus, you can get rid of the if()
statement altogether:

void SetLinesLength(TRichEdit* p, int length)
That is much better code. But it has the same effect as Oren's
original code. The unwanted behaviour is caused by wordwrapping.
Hans.
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

On Sun, 29 Feb 2004 23:13:53 +0100, Oren Halvani wrote:
Quote
I found a strange bug in my application...
I'm setting the length of each Line in RichEdit to (for example) "6"
Is WordWrap on for your richedit?
--
Good luck,
liz
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

thanks folks, works now exactly like I wanted :-)
Oren
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

Oren Halvani wrote:
Quote
thanks folks, works now exactly like I wanted :-)
Could you please be more informative in what caused your problems
and in which way you solved them ?
Stating 'It works now.' after you got several replies is as
informative as stating 'It does not work.' when posting questions.
Hans.
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

"Hans Galema" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Could you please be more informative in what caused your problems
and in which way you solved them ?

Stating 'It works now.' after you got several replies is as
informative as stating 'It does not work.' when posting questions.

Hans.
sorry hans, remys snip[] was my solution:
/******************************************/
void SetLinesLength(TRichEdit* p, int length)
{
Screen->Cursor = crHourGlass;
try
{
p->Lines->BeginUpdate();
try
{
for(int x = 0; x < p->Lines->Count; ++x)
{
AnsiString s = p->Lines->Strings[x];
if( s.Length()>length )
p->Lines->Strings[x] = s.SetLength(length);
}
}
__finally {
p->Lines->EndUpdate();
}
}
__finally {
Screen->Cursor = crDefault;
}
}
 

Re:Setting the length of RichEdit->Line[x] function need to be called several times to sucseed...

Oren Halvani wrote:
Quote
sorry hans, remys snip[] was my solution:
That is hard to believe. Tested your and Remy's implementation
and they did the same on the files I tested.
Only wordwrapping true caused the problems.
Hans.