2
votes

In a TMemo field I have 3 lines:

  1. line1
  2. line2
  3. line3

Is it posible to get all three lines as one string?

Example:

line1,line2,line3

3
Whoa, why all the downvotes? Just tell this guy how to improve his question if you think something is wrong - Wouter van Nifterick

3 Answers

6
votes

You can use the Lines.CommaText property for this. Do the following:

CommaString := Memo1.Lines.CommaText;

Its also useful to use the DelimitedText property if you want the text to make use of another separator character. You can do that by using something like this:

Memo1.Lines.Delimiter := '-';
Memo1.Lines.StrictDelimiter := True;
DashString := Memo1.Lines.DelimitedText;

This works both ways. You can assign a value to the CommaText or DelimiterText to set the lines. This is actually a of TStringList so it will work with TListBox, TMemo, TComboBox, etc. Basically anything that uses a string list internally.

0
votes

maybe something like this suits your needs

d:=memo1.lines.count;
for i:=1 to d do
   memo1.lines[0]:=memo1.lines[0]+' '+memo1.lines[i];
for i:=1 to d do
   memo1.lines.Delete(1);
-4
votes

here is a 3 line function that do it.

function getOneLineMemo(memo:Tmemo):String;
var
  i:integer;
begin
  result := '';
  for i:=0 to memo1.lines.count do
     result := result + memo.lines[0];
end;