In the never-ending saga that is my application, I have discovered that my text search fails (ie using PosEx fails to correctly locate the search characters in the TMemo) if I assign lines read from a file to a TMemo using TMemo.Lines := strList rather than TMemo.Text := strList.Text.where do you search at Memo.Text or Memo.Lines.Text? (something else?)
It appears to me to be related to the number of lines and therefore likely the LineEndings are causing the issue.
In the never-ending saga that is my application, I have discovered that my text search fails (ie using PosEx fails to correctly locate the search characters in the TMemo) if I assign lines read from a file to a TMemo using TMemo.Lines := strList rather than TMemo.Text := strList.Text.where do you search at Memo.Text or Memo.Lines.Text? (something else?)
It appears to me to be related to the number of lines and therefore likely the LineEndings are causing the issue.
Did you use posex(substr,wholestr,value) and not (wholestr,substr). Show more code.
Note also that for memos it's best to use UTF8Pos() and UTF8RPos(). Pos(), PosEx(), RPos(), etc. tend to fail for anything other than single-byte character strings.
Another thing to take into account: The string functions return a 1-based position but SelStart, etc. are 0-based.
try r61567 please
Memo.SelStart := PosEx(UpperCase(Edit.Text), UpperCase(Memo.Text), searchOFS) - 1;
Try using:
Memo.Lines.AddStrings(StringList, True);
or even
Memo.Lines.Assign(StringList);
Any of those should work right everywhere.
Also, I'm assuming (because your "we have a match") that you test that PosEx > 0 somewhere? If not your search should be more like:
try r61567 please
Thanks Dmitry - yes, that fixed the text location issue.Keep that in mind: https://wiki.lazarus.freepascal.org/Cocoa_Internals/Text_Controls#Forcing_Lines_Breaks