Delphi and the joy of Compiler Intrinsics – I cant use “Length” as a TFunc…
Posted by jpluimers on 2017/04/18
One of the reasons I favour using RTL based functionality over Delphi Intrinsic Routines like Length, Abs and others is that you cannot use compiler intrinsics in Generics. For instance Length is not compatible with TFunc<string, Integer> unless you declare it yourself like function StringLength(value: string): Integer;
as otherwise you get en E2029 error (in this case the cryptic '(' expected but ';' found
).
It’s one of the many areas where the Delphi compiler developers took a shortcut, but in this case I think the results are somewhat good.
Other reasons for using the RTL over compiler intrinsics have to do with scoping: the intrinsics are in the global scope which can clutter what you’re trying to work on.
So I much rather use the file and stream related functions when I’m actually working with a file or stream. For instance Assign for me has nothing to do with a file outside of a file context (it’s the reason AssignFile exists in the first place).
–jeroen
via: I cant use “Length” as a TFunc (tested in XE and XE6), but if…
Chee Wee said
Unless you intend to modify the string, you should use const when declaring the string as the parameter to the function.