Board index » delphi » TMemo selected text

TMemo selected text

I'm trying to write routines that operate only on the selected lines in a
memo component. I'm confused because the 'SelText' property of TMemo is of
type 'string' , not 'strings'. If I want to process this selected text on a
line by line basis, must I first convert it to PChar or something like that?
Help, this is all new to me.
Mac
 

Re:TMemo selected text


Michael,

The following example copies the selected text in a memo component (moMain)
to an edit component (edMain). Please note that when the selected text
contains multiple lines then the text copied will include CR/LF which
separate the lines.

procedure TForm1.Button1Click(Sender: TObject);
begin
  edMain.Text:= Copy(moMain.Text, moMain.SelStart, moMain.SelLength);
end;

Hope this helps,
--
Prolix Webmaster
http://www.prolix.be
The best newsgroup archive available

Quote
"Michael Dawson" <friedandfo...@bigpond.com> wrote in message

news:3b2af1a4$1_1@dnews...
Quote
> I'm trying to write routines that operate only on the selected lines in a
> memo component. I'm confused because the 'SelText' property of TMemo is of
> type 'string' , not 'strings'. If I want to process this selected text on
a
> line by line basis, must I first convert it to PChar or something like
that?
> Help, this is all new to me.
> Mac

Re:TMemo selected text


Quote
In article <3b2af1a4$1_1@dnews>, Michael Dawson wrote:
> I'm trying to write routines that operate only on the selected lines in a
> memo component. I'm confused because the 'SelText' property of TMemo is of
> type 'string' , not 'strings'. If I want to process this selected text on a
> line by line basis, must I first convert it to PChar or something like that?

If the selection contains more than one line then you can dissect it using an
intermediate TStringlist:

  var
    sl: TStringlist;
    i: integer;
  begin
    sl:= Tstringlist.create;
    try
      sl.text := memo1.seltext;
      for i:= 0 to sl.count-1 do
        ...something with sl[i]
    finally
      sl.free
    end;

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads