The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,756 other followers

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…

One Response to “Delphi and the joy of Compiler Intrinsics – I cant use “Length” as a TFunc…”

  1. Chee Wee said

    Unless you intend to modify the string, you should use const when declaring the string as the parameter to the function.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: