How to Remove Blank Lines from Memo?

The other day I had a TMemo in my application where the user reported some observation of the product.
So, in some cases, I started to have a printing problem because the field was taking up too much space.
After checking, I noticed how many times the user was putting several blank lines at the end of TMemo without realizing it, so I thought of an automatic way to remove these blank lines at the end of the field.
Well, initially I came up with a code like this:
procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin for i := Memo1.Lines.Count/1 downto 0 do if trim(Memo1.Lines[i]) = '' then Memo1.Lines.Delete(i); end;
Okay, it works, but what if you need it for RichEdit or other types of lists?
Improving the Code!
Let’s create a procedure to be able to use this feature in several places!
procedure RemoverwhiteLines(aList : TStrings); var i: integer; begin for i := aList .Count downto 0 do if (Trim(aList [i]) = '') then begin aList.Delete(i); end; end; Now for an example of use with the procedure.
// Example with memo procedure TForm1.Button1Click(Sender: TObject); begin RemoverwhiteLines(Memo1.Lines); end; // Example with RichEdit procedure TForm1.Button1Click(Sender: TObject); begin RemoverwhiteLines(RichEdit1.Lines); end;
I hope I can help.
Regards and see you next post.