Find Next in Memo - doesnt show word lazarus / 21-General ---------------------------------------------------------------------- Raf20076 · 2021-01-24 10:12 Hi Guys I have Find Next procedure in Memo but it doesn't work correctly. It doesn't highlight word correctly when it found. Also it doesn't highlight the last word if found. Something is wrong with position. I need UTF8 in this example. Have you got any ideas? Thanks Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit main; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,  ComCtrls,LazFileUtils, LCLProc, LazUtils, LazUtf8, Variants, strutils; type   { TForm1 }   TForm1 = class(TForm)    CheckButton: TButton;    Memo: TMemo;    procedure CheckButtonClick(Sender: TObject);   private   public   end; var  Form1: TForm1;  SearchAfterPos: Integer=0;  implementation {$R *.lfm} { TForm1 }   procedure TForm1.CheckButtonClick(Sender: TObject);//var  s: string;  i, searchstart: Integer;  Selected : String;  begin   searchstart:=Memo.SelStart+Memo.SelLength+1;  Selected := 'łabędź';//find this word   searchstart:=SearchAfterPos+1;  s := Copy(Memo.Text, searchstart, length(Memo.Text)-(searchstart));  i := PosEx(Selected, s);  if (i <> 0) then  begin     Memo.SelStart := (i-2)+(searchstart);    Memo.SelLength := Length(Selected);    Memo.SetFocus;    SearchAfterPos:=SearchAfterPos+i+Length(Selected)-1;    end else begin    ShowMessage('The word is found no further.');     SearchAfterPos:=0;     end;end; end. ---------------------------------------------------------------------- paweld · 2021-01-24 11:15 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i s := Copy(Memo1.Text, searchstart, length(Memo1.Text) - (searchstart) + 1); ---------------------------------------------------------------------- Raf20076 · 2021-01-24 11:18 Thanks I changed my code adding UTF8Length insted of Length, UTF8copy insted of Copy and and it seems to works now. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit main; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,  ComCtrls,LazFileUtils, LCLProc, LazUtils, LazUtf8, Variants, strutils; type   { TForm1 }   TForm1 = class(TForm)    CheckButton: TButton;    Memo: TMemo;    procedure CheckButtonClick(Sender: TObject);   private   public   end; var  Form1: TForm1;  SearchAfterPos: Integer=0;  implementation {$R *.lfm} { TForm1 }   procedure TForm1.CheckButtonClick(Sender: TObject);//var  s: string;  i, searchstart: Integer;  Selected : String;  begin   searchstart:=Memo.SelStart+Memo.SelLength+1;  Selected := 'łabędź';  searchstart:=SearchAfterPos+1;  s := UTF8copy(Memo.Text, searchstart, length(Memo.Text)-(searchstart));//changed to UTF8  i := PosEx(Selected, s);  if (i <> 0) then  begin     Memo.SelStart := (i-2)+(searchstart);    Memo.SelLength := UTF8Length(Selected);//changed to UTF8    Memo.SetFocus;    SearchAfterPos:=SearchAfterPos+i+UTF8Length(Selected)-1;//changed to UTF8    end else begin    ShowMessage('The word is found no further.');     SearchAfterPos:=0;     end;end; end.