Solved

Convert TMemo.Lines to a single long string

Posted on 1998-12-11
14
245 Views
Last Modified: 2010-04-04
Using Delphi 2/3, how can one take the entire contents of Memo1 and place it into a single long string?
0
Comment
Question by:Monroe406
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1350746
How about this??

var
  LongStr : string;
  i : integer;
begin
  LongStr := '';
  for i := 0 to MemoName.Lines.Count - 1 do
    LongStr := LongStr + MemoName.Lines[i];
  ShowMessage(LongStr);
end;

Hope this helps.

Cheers,
Viktor
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350747
Personally I prefer this:

var
  TheMemoText : String;

TheMemoText := Memo1.text;

Cheers,

Raymond.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350748
Yeah, but that way you won't get the line feed characters like #13 and #10... Otherwise that way is easier if you don't want to have the line feed chars... :))

Cheers,
Viktor
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350749
Actually you do get the linefeeds!

Put 2 memos and a button on a form, put some text (a few lines) in one of the memos. IN the onclick of the button do this:

memo2.text := memo1.text;

Hey presto - the line breaks are preserved!

Cheers,

Raymond.

0
 
LVL 3

Expert Comment

by:williams2
ID: 1350750
Hmm Interesting Raymond, I actually never thought of that, anyway I shouldn't, I'm doing a fulltime ICQ system at the moment :-)

Regards,
Williams
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350751
Raymond... That's not true... I haven't tested that, so I don't want to argue, but don't do the memo1.text := memo2.text;

do this...

var
  str : string;
begin
 str := memo2.text;
 memo1.text := str;
end;

If this works as supposted then Raymond is right... there is one point to make...
0
 

Author Comment

by:Monroe406
ID: 1350752
>> but don't do the memo1.text :=  memo2.text;

To viktonet:  Although it is not relevant to my original question, I would like to know why would I not want to do the above?  It works!  Therefore what's wrong with this?

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350753
hello all...

Well, I just tried it and I want to apologize to Raymond, Monroe and all others with my statment above. It works even if you do str := memo1.text. I thought it would lose the #13#10 characters.... Sorry for the misunderstanding...

btw- Can someone try this and tell me what happens 'cuz i don't have mcuh time,,,

var
  str : string;
  i : integer;
begin
  str := '';
  for i := 0 to Memo1.lines.counte - 1 do
    str := str = memo1.lines[i];
  showmessage(str);
end;

Do the characters for line feed show up?? Is the message wrapped like u saw it in the memo or is it a long line that doesn't wrap?? 10x to all

Cheers,
Viktor
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350754
(Again without trying it) I think this will strip out the line feeds as the lines property gives individual lines which are terminated by the length/#0 combination of ANSIStrings and not #10#13 sequences.

Anyway, you got the points :-)

Cheers,

Raymond,
0
 

Author Comment

by:Monroe406
ID: 1350755
>>Can someone try this and tell me what happens 'cuz i don't have mcuh time,,,


If Memo1 contains...

Line1
Line2
Line3

and I use your "tell me what happens" code, then the ShowMessage will display:

   "Line1Line2Line"

0
 

Author Comment

by:Monroe406
ID: 1350756
>>Can someone try this and tell me what happens 'cuz i don't have mcuh time,,,


If Memo1 contains...

Line1
Line2
Line3

and I use your "tell me what happens" code, then the ShowMessage will display:

   "Line1Line2Line3"

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350757
If what Monroe tells is true then I was right, but just swapped the functions... if you use memo1.text then the line feed char will be there and if you use the lines[count] thing then it will not be there...

Cheers,
Viktor
0
 

Author Comment

by:Monroe406
ID: 1350758
>>if you use memo1.text then the line
>> feed char will be there and if you use the lines[count]
>> thing then it will not be there...


That is correct
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350759
yup ;o)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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