Forum > General
TArrayHelper
avk:
--- Quote from: Thaddy on November 06, 2025, 09:48:36 am ---BTW: the above compiles with 3.2.2 too.
--- End quote ---
Of course not, FPC-3.2.2 requires a different comparator signature.
jamie:
Good luck getting that to work in a serious application I have given up on using anything from the collections the compiler will choke on it with untraceable error at the end of the main source.
Also I already implemented a class using the custom array helper in there why would you lard up the code so badly using interfaces to start with?
If you are looking for auto cleanup at the end of the use you could do much better using advanced records where you can initiate automatically at the start and clean up without additional intervention code .
Have it your way lard and choke the compiler or efficiency and make it work.
Thaddy:
Well, opinions differ. I found it a bit erratic that you came up with something that is not even in the rtl and nobody ever heared of.
The question is obviously for the rtl.
For completeness binarysearch:
--- 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";}};} --- // add a var named Idx:SizeInt; R.min := 100; R.max := 200; writeln(TArrayHelper<TARecord>.BinarySearch(RecordArray, R,Idx, MinComparer)); writeln(idx);// idx is one based. Subtract 1 for the true index.
One remark: there are indeed very few simple and practical examples on how to use rtl-generics. Even for Delphi. I had a look at the tests.
ginoo:
@Thaddy Thanks, great example. I think you could post it on the wiki; it would be helpful.
@avk. For fpc3.2.2, just replace constref with const
Thaddy:
--- Quote from: avk on November 06, 2025, 11:40:14 am ---Of course not, FPC-3.2.2 requires a different comparator signature.
--- End quote ---
You are right. I compiled the test with 3.2.3.... (Bug fixed) I did not realize that I compiled for 3.2.3. My main compilers are always, well, ...main.
https://wiki.freepascal.org/User_Changes_3.2.4 // in this case matches 3.2.3
But I should have been more careful. 3.2.2 or lower needs constref, which is not optimal.
Navigation
[0] Message Index
[#] Next page
[*] Previous page