Forum > Other OS

[SOLVED] macOS: TMemo.Lines vs TMemo.Text and PosEx()

(1/3) > >>

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

It appears to me to be related to the number of lines and therefore likely the LineEndings are causing the issue.

macOS 10.14.5, Lazarus v2.10 (trunk), FPC 3.0.4 or FPC 3.3.1 (trunk).

Curiously it works fine under:

o  Ubuntu 18.04 64 bit with Lazarus v1.8.2; FPC v3.0.4;
o  FreeBSD 12.0 64 bit with Lazarus v2.00;  FPC v3.0.4; and
o  Windows 10 64 bit cross-compiled under macOS for 32 bit

using either method.

Easy enough to work around now that I figured out what is going on, but... I doubt it should be happening.

skalogryz:

--- Quote from: trev on July 10, 2019, 02:36:44 pm ---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.

It appears to me to be related to the number of lines and therefore likely the LineEndings are causing the issue.

--- End quote ---
where do you search at Memo.Text or Memo.Lines.Text? (something else?)

marcov:
Did you use posex(substr,wholestr,value) and not  (wholestr,substr). Show more code.

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

And that's not counting the problems with UTF8-BOM, ZWJs, etc. :)

trev:

--- Quote from: skalogryz on July 10, 2019, 03:15:27 pm ---
--- Quote from: trev on July 10, 2019, 02:36:44 pm ---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.

It appears to me to be related to the number of lines and therefore likely the LineEndings are causing the issue.

--- End quote ---
where do you search at Memo.Text or Memo.Lines.Text? (something else?)

--- End quote ---


--- 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";}};} ---  // we have a match...  else    begin      // select characters to highlight      Memo.SelStart := PosEx(UpperCase(Edit.Text), UpperCase(Memo.Text), searchOFS) - 1;      Memo.SelLength := Length(Edit.Text);      searchOFS := Memo.SelStart + 1;    end;     

Navigation

[0] Message Index

[#] Next page

Go to full version