Hi guys I have written Lazspell, an example of spelling checker and I have one problem with UTF8.
https://github.com/Raf20076/Lazspell-2-version-2.
In Function unit
https://github.com/Raf20076/Lazspell-2-version-2/blob/main/functions.pas in function FindInMemo seems to me that one character is showed less.
When I run Lazspell-2-version-2
I choose pl_PL dictionary and in Memo I type
test tes
then I click button
Check, in
Errors window is showed
tes as an error.
I click
tes in
Errors window and in Memo word
test is underlined (only tree characters tes) not next word tes.
test tes
So it seem to me that something is wrong with position.
This copies one character less - example:
In Memo there is only the word test so the length is 4, and now it copies from 1 character (ok) but 4-1, which is 3, so it won't have TEST, just TES. Polish letters are 2 bytes each. All strings in FindIn Memo must converted to utf8
but this one
Result := UTF8Pos(AString, AMemo.Text, StartPos);
doesn't work.
function FindInMemo(AMemo: TRichMemo; AString: String; StartPos: Integer): Integer;
{Find clicked error (word) from ListBoxErrors and highligh it}
//This function must be maybe rewritten and more testing including proper character calculation in UTF8
begin
//Result := UTF8Pos(AString, AMemo.Text, StartPos);//Seems not working
Result := PosEx(AString, AMemo.Text, StartPos);
If Result > 0 then
begin
AMemo.SelStart := UTF8Length(PChar(AMemo.Text), Result - 1);
AMemo.SelLength := UTF8Length(AString);
AMemo.SetRangeParams(AMemo.SelStart, AMemo.SelLength,[tmm_Styles, tmm_Color],'',0,clRed,[fsBold,fsUnderLine],[]);
//In RichMemo HideSelection must be set to True
end;
Any ideas
Thanks