Delphi sorcery: New language feature in XE7


http://delphisorcery.blogspot.com/2014/10/new-language-feature-in-xe7.html

Comments

  1. Awesome post!
    And I fully agree with your NameOf suggestion. I've made the same suggestion before, because using hand crafted strings is error prone and not refactoring safe. It needs to work for properties and methods.

    From a error logging perspective, it would be nice to have a CurrentCodeLocation function as well, because unwinding the stack is costly and not always necessary.

    ReplyDelete
  2. if GetTypeKind(T: TypeIdentifier) returns real contant then it is super-puper feature!!

    Now we can write something like this:
    procedure TFoo.Bar(const AParam: T);
    const TK = GetTypeKind(T);
    begin
       {$if not (TK in [tkInteger, tkString])}
          {$message error 'TFoo.Bar can be used with integer and string only'} // _compile time_ check!!!
       {$endif}
     // assume AParam in string or integer
      
    end;

    ReplyDelete
  3. Stefan Glienke I think, it would be cool, if there is something like static_assert in C++. Then my example can rewrite : StaticAssert(GetTypeKind(T) in [tkInteger, tkString]).
    To  improve constraints is good, but static_assert is easy to implement as I believe

    ReplyDelete

Post a Comment