Solved

Convert TMemo.Lines to a single long string

Posted on 1998-12-11
14
244 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

14 Experts available now in Live!

Get 1:1 Help Now