Board index » cppbuilder » TRichEdit Empty Line Problem

TRichEdit Empty Line Problem


  I am using BCB 3.0 Standard and I am having problems outputting SQL
queries from a program that takes queries and outputs the results.  The
program that is used to do queries uses a TRichEdit component. I am using
Sybase as my  way of resolving queries.  Whenever I send the results from a
query directly to a file I do not worry about empty lines (return
characters) inserted out of nowhere (YAY!!).  However, if I want to output
the results directly to the screen (i.e. the TRich component displays the
results) I see empty lines whenever the local buffer limit has been reached.
The buffer is set at (by default) 256KB.  Internally, the next row in the
results is converted from a string to a null-terminated character array
(using c_str()).  All I'm doing is checking to see if the next row has
enough room to be placed in the buffer.  Here is how I clear the buffer (I
use TStrings to keep the rows), how I add a string to the result if it fits
into the buffer, and how I attempt (yes, it's ugly) to delete the unwanted
empty line in case one is met:

/*Local Buffer*/
#define LOCAL_BUF_SIZE (262144)  // 2^18
static int  lb_len;
static char lb[LOCAL_BUF_SIZE];

/*clear the buffer*/
void TfMain::CopyBuffer2Control()
  StatusBar->SimpleText = StatusBar->SimpleText + " ( Flushing Buffer
... )";  /*appears only when no more room in the buffer*/
/*write the results thus far to the screen*/

   memset( lb, 0, LOCAL_BUF_SIZE );
/*refresh the buffer, LOCAL_BUF_SIZE is currently at 262144

/*or lb_len = 0;  lb[lb_len] = 0;  does same thing*/


 /*How I see if a row is to be put in the buffer*/
void TfMain::AppendLine( char const * aLine )

  if ( FileHandle != NULL )
    fprintf ( FileHandle, "%s\n", aLine );           /*this is only to
output to a file which works 100%, ignore it*/

  if(strlen(aLine)==0)                                   /*Empty line met?*/
      /*MessageBox (NULL, "Empty Row", "Empty line", MB_OK );*/     /*here
I'm trying to explicitly ignore adding the empty line and yet it doesn't
work  :(

     if ( strlen(lb) + strlen(aLine) + strlen("\n") >= LOCAL_BUF_SIZE )
/*make room for the new row coming in*/

       sprintf (lb + strlen(lb), "%s\n", aLine);


/*Here was another way I tried to explicitly delete the empty line if
encountered:  (relevant code showed)

StatusBar->SimpleText = "Running Query...";

/*Below part is by a programmer who worked on this project two years ago*/
if ( Text1->SelText.IsEmpty() )
      ExecuteQueryList ( Text1->Lines );
    else                                 // text selected ? execute it
      SelTextQuery->Text = Text1->SelText;

      SelTextQuery->Lines->Strings[0].c_str();  // C++ builder bug ?

      ExecuteQueryList ( SelTextQuery->Lines );

/*And now ... */

   for ( int kk=0; kk <= Result->Lines->Count; kk++ )
        if (strlen(Result->Lines->Strings[kk].c_str()) == 0)
              Result->Lines->Delete(kk);                                /*
"pretends" to delete the line*/

  And no empty line is removed.  I know that if I want to remove, say (kk+1)
row, it is removed, but not the row displayed that contains nothing. It is
very annoying!!  I tried doubling the buffer limit and then only one empty
line shows in the display.  If I quadruple the buffer, NO empty line shows.
This leads me to believe that as long as I don't have to access and to flush
the buffer I don't get empty lines.  Does anyone know if there's a problem
when emptying the buffer in RichEdit? What's the best way to delete the
empty lines as I encounter them in my search?  On my system are the
"Riched32.dll" and "riched20.dll" and both seem to be used by BCB (I tried
to remove either one and when recompiling the program BCB did not like it).

 Once again, if I output the results to a file, eveything works well.  But
if I want to output to the screen some empty lines are inserted.

            Thank you for any help,


Re:TRichEdit Empty Line Problem

>   if ( FileHandle != NULL )
>     fprintf ( FileHandle, "%s\n", aLine );           /*this is only to
> output to a file which works 100%, ignore it*/


If this works great, why don't you try using sprintf().

Another idea...

I may have had a similar problem with a Richedit string and I did...

String Form::stripBackSlashRN(String S)
    if( S == NULL || S == "" ) return S;
    while( S[S.Length()] == '\r' || S[S.Length()] == '\n' )
           S = S.SubString(1,S.Length()-1);
    return S;


You can pass this method a char* and it will work, gets converted to a
String.  Then use stripBackSlashRN( ln ).c_str() to get back to a char*.
Only I use BCB v 4.  Hope this works for you.

Re:TRichEdit Empty Line Problem

Hi, Dragos.

I know of at least one hard-coded 4K buffer in the TRichEdit VCL Lines
code.  You might try resizing your buffers to < 4K or using the WinAPI
to manipulate text in the TRichEdit.

You mentioned that the TRichEdit/VCL seems to require riched20.dll.  If
this is correct and you are not using Win2K, then please let me know
(this would be news to me).  If you are using Win2K and would like an
explanation, just say so.



Other Threads