Solved

Convert TMemo.Lines to a single long string

Posted on 1998-12-11
14
243 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
Comment Utility
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
Comment Utility
Personally I prefer this:

var
  TheMemoText : String;

TheMemoText := Memo1.text;

Cheers,

Raymond.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
(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
Comment Utility
>>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
Comment Utility
>>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
Comment Utility
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
Comment Utility
>>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
Comment Utility
yup ;o)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now