The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

    • RT @nadineswagerman: Iemand mailde me dat een 13-jarig meisje mijn novelle had uitgekozen om te lezen/bespreken op school. Het boek bevat 9… 6 hours ago
    • RT @jilles_com: Afgelopen 10 dagen hebben we door NL gereisd, elke dag een nieuw hotel en op heel veel locaties gegeten. In 60% van de geva… 6 hours ago
    • RT @FTM_nl: Sywert van Lienden plaatste bewust een serie tweets om het ministerie onder druk te zetten om de omstreden mondkapjesdeal met h… 6 hours ago
    • RT @ArmsControlWonk: China just used a rocket to put a space plane in orbit and the space plane glided back to earth. Orbital bombardment i… 6 hours ago
    • RT @shossontwits: O jee. Nu dit weer. 6 hours ago
  • My Flickr Stream

  • Pages

  • All categories

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

    Join 2,482 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).


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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: