Forum > Other OS
[SOLVED] macOS: TMemo.Lines vs TMemo.Text and PosEx()
trev:
--- Quote from: marcov on July 10, 2019, 04:24:54 pm ---Did you use posex(substr,wholestr,value) and not (wholestr,substr). Show more code.
--- End quote ---
Yes, see above.
trev:
--- Quote from: lucamar on July 10, 2019, 05:40:40 pm ---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.
--- End quote ---
The files contain PIC microcontroller config word settings, registers, interrupts etc and are definitely always going to be single byte characters... yeah, I know, famous last words ;)
--- Quote ---Another thing to take into account: The string functions return a 1-based position but SelStart, etc. are 0-based.
--- End quote ---
Aware and accounted for.
lucamar:
Try using:
--- 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";}};} ---Memo.Lines.AddStrings(StringList, True);or even
--- 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";}};} ---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 lke:
--- 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 searchOFS := PosEx(UpperCase(Edit.Text), UpperCase(Memo.Text), searchOFS); if searchOFS > 0 then begin Memo.SelStart := searchOFS - 1; Memo.SelLength := Length(Edit.Text); end else ShowMessage('Not found'); end;
skalogryz:
--- Quote from: trev on July 11, 2019, 08:33:24 am ---
--- 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";}};} --- Memo.SelStart := PosEx(UpperCase(Edit.Text), UpperCase(Memo.Text), searchOFS) - 1;
--- End quote ---
try r61567 please
trev:
--- Quote from: lucamar on July 11, 2019, 02:25:18 pm ---Try using:
--- 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";}};} ---Memo.Lines.AddStrings(StringList, True);
--- End quote ---
The assignment with the above takes approx 10s vs 1ms for:
--- 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";}};} ---Memo.Text := strList.Text;
--- Quote ---or even
--- 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";}};} ---Memo.Lines.Assign(StringList);
Any of those should work right everywhere.
--- End quote ---
Only at the cost of a huge performance hit (28s): see https://forum.lazarus.freepascal.org/index.php/topic,45733.0.html
--- Quote ---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:
--- End quote ---
You assumed right.
Navigation
[0] Message Index
[#] Next page
[*] Previous page