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
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.