Remove blank lines in RichEdit

Hi Experts,

Im using a TwwDBRichEdit component.
At runtime, this will contains the following lines:

+LastName+
+FirstName+
+MiddleInitial+
+Address1+
+Address2+
+City+
+State+
+Zip+


+CurrentDate+

Upon hitting a button, this will be replace with values coming from a table.
Hitting a second button, this will then be printed (hardcopy).
My problem is that there are times when +MiddleInitial+ and +Address2+ will be blank and I want to delete (remove) this particular line(s) upon printing.

For example, instead of:

Smith
John
B
888 Plainfield

Edison
New Jersey
08820


04/24/06


It will be printed as:

Smith
John
B
888 Plainfield
Edison
New Jersey
08820


04/24/06

============================

Smith
John

888 Plainfield
Middlesex
Edison
New Jersey
08820


04/24/06


It will be printed as:

Smith
John
888 Plainfield
Middlesex
Edison
New Jersey
08820


04/24/06

============================

Smith
John

888 Plainfield

Edison
New Jersey
08820


04/24/06


It will be printed as:

Smith
John
888 Plainfield
Edison
New Jersey
08820


04/24/06

==============================


Can this be done?

Please show me sample code lines.

I been using #13 (Carriage Return) and #10 (Line Feed) on my coding but just don't know what do use for a line delete.

I'm using Delphi 6

TIA
Yorge
yorgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heretoreadCommented:
var
  I:Integer;
begin
for I:= RichEdit.Lines.Count -1 downto 0 do
  if RichEdit.Lines[I] = '' then
    RichEdit.Lines.Delete(I);
end;

That code assumes that the component you are using has a TStrings\List property.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mokuleCommented:
var
  i: integer;
begin
  for i := RichEdit.Lines.Count -4 downto 0 do    // this will left you two empty lines before date line
    if Length(Trim(RichEdit.Lines[i])) = 0 then    // this will delete lines with spaces only
      RichEdit.Lines.Delete(i);
end;

0
ZhaawZSoftware DeveloperCommented:
example of heretoread would work incorrectly if there is sequence of several empty rows (for example, 2nd and 3rd rows are empty; it checks 2nd row and deletes it; now "previously 3rd row" becomes 2nd row and stays unchecked because loop checks the next row).

example of mokule should work perfect (just could be checked «if trim(richedit.lines[i]) = ''» instead of «if length() = 0»)

another thing is usage of BeginUpdate and EndUpdate if working with large number of lines.
>> RichEdit1.Lines.BeginUpdate;
>> i := 0;
>> while i < RichEdit1.Lines.Count - 3 do if trim(RichEdit1.Lines[i]) = '' then RichEdit1.Lines.Delete(i) else inc(i);
>> RichEdit1.Lines.EndUpdate;
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

mokuleCommented:
Have I better name that mine program would work better?
Thanks Zhaawz. But it's not truth :)
I've mostly copied heretoread.
0
heretoreadCommented:
It works fine, it starts from the top deleting down.

I'm guessing you had a quick look and thought i used
for I:= 0 to RichEdit.Lines.Count - 1 do
0
ZhaawZSoftware DeveloperCommented:
err.. sorry, you're right ;)
0
korayboluk1Commented:
procedure RemoveBlankRich(RichEdt : TRichEdit);
var
          i,Count   : Integer;
          sLine : String;
          Label Reloop;//holds empty lines
begin
          //First remove all empty lines
          Reloop:
          for i:=0 to RichEdt.Lines.Count-1 do
             begin
              if Trim(RichEdt.Lines.Strings[i]) = EmptyStr then
                 begin
                     RichEdt.Lines.Delete(i);
                     Goto Reloop;
                 end;
             end;

end;

Usage RemoveBlankRich(Richedit you use)
0
korayboluk1Commented:
on Label Reloop it writes hold empty lines it is a wrong comment Sorry:(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.