Solved

Convert TMemo.Lines to a single long string

Posted on 1998-12-11
14
254 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
Industry Leaders: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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