Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Remove blank lines in RichEdit

Posted on 2006-04-24
10
Medium Priority
?
1,484 Views
Last Modified: 2013-11-22
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
0
Comment
Question by:yorge
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Accepted Solution

by:
heretoread earned 300 total points
ID: 16527582
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
 
LVL 17

Expert Comment

by:mokule
ID: 16527828
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
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 16533618
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Expert Comment

by:mokule
ID: 16533722
Have I better name that mine program would work better?
Thanks Zhaawz. But it's not truth :)
I've mostly copied heretoread.
0
 
LVL 2

Expert Comment

by:heretoread
ID: 16533961
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
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 16534170
err.. sorry, you're right ;)
0
 

Expert Comment

by:korayboluk1
ID: 16647736
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
 

Expert Comment

by:korayboluk1
ID: 16647747
on Label Reloop it writes hold empty lines it is a wrong comment Sorry:(
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Integration Management Part 2
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question