Solved

Convert TMemo.Lines to a single long string

Posted on 1998-12-11
14
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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