Recent

Author Topic: Highlight Memo line on double click  (Read 8007 times)

Roman

  • New Member
  • *
  • Posts: 25
Highlight Memo line on double click
« on: January 05, 2012, 09:21:27 pm »
I'am trying to select a line in memo by double clicking into that line. Code is simple:

Code: [Select]
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
  with Memo1 do
  begin
    SelStart:=SelStart-CaretPos.x;
    SelLength:=Length(Lines[CaretPos.y])
  end
end;   

but I get highlighted few characters from the end of previous line and almost whole line where caret is. What I am doing wrong?

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Highlight Memo line on double click
« Reply #1 on: January 06, 2012, 06:39:48 am »
procedure TForm1.Memo1DblClick(Sender: TObject);
var
  Row, Col: Integer;
begin
  Col:= Memo1.CaretPos.x;
  Row:= Memo1.CaretPos.y;
  Memo1.SelStart:= Memo1.SelStart+Memo1.SelLength-Col;
  Memo1.SelLength:= Length(Memo1.Lines[Row]);
end;
Lazarus Trunk / fpc 2.6.2 / Win32

Roman

  • New Member
  • *
  • Posts: 25
Re: Highlight Memo line on double click
« Reply #2 on: January 06, 2012, 07:37:21 am »
This is it, thank you.

 

TinyPortal © 2005-2018