Forum > General

[SOLVED] Highlight a particular line of a memo

<< < (2/3) > >>

winni:
Hi!

Utf8ength must be used, that is correct.

But you forget to add the

length(lineEnding)


Dont add just one ore two because Linux and Windows have a different length of the LineEnding

Winni

w click:
Thank you, much appreciated.  This worked.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      if (target>-1)and(target<=Memo1.lines.count-1) then begin      count:=0; i:=0;      while i<target do begin        count:=count+utf8length(Memo1.lines[i])+utf8length(lineending);        i:=i+1;      end;      Memo1.selstart:=count;      Memo1.SelLength:=utf8length(Memo1.lines[target]);      Memo1.setfocus;    end; 

ASerge:

--- Quote from: w click on June 19, 2022, 03:21:09 pm ---Thank you, much appreciated.  This worked.

--- End quote ---
In first topic you say "without assigning selstart".
Here is an example. It only reads the SelStart property. And no loops and UTF 8 function calls:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure SelectLineInMemo(Memo: TCustomMemo; LineIndex: SizeInt);var  SelEnd: SizeInt;begin  Memo.CaretPos := Point(0, LineIndex + 1); // It also works for last LineIndex  SelEnd := Memo.SelStart;  Memo.CaretPos := Point(0, LineIndex);  Memo.SelLength := SelEnd - Memo.SelStart;end;

w click:
I couldn't get point to work, I'm afraid.

speter:

--- Quote from: w click on June 26, 2022, 04:42:16 pm ---I couldn't get point to work, I'm afraid.
--- End quote ---

You may need to add "types" or ""classes" to your unit "uses" line.

cheers
S.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit something; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms;// ^^^^

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version