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

  • Pages

  • All categories

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

    Join 1,310 other followers

Delphi analog to C# ?? null-coalescing operator and Light Table like debugger evaluation

Posted by jpluimers on 2017/09/05

Interesting stuff:

via:

In more detail:

Source: 2016-10-15 – Zenryokuwawa

And:

type
  TObjectHelper = class helper for TObject
  public
    class function &&op_LogicalOr(A, B: T): T; static;
  end;

class function TObjectHelper.&&op_LogicalOr(A, B: T): T;
begin
  if A <> nil then
    Result := A
  else
    Result := B;
end;

procedure Test;
var
  sl1, sl2, sl3: TStringList;
begin
  sl1 := nil;
  sl2 := TStringList.Create;
  sl3 := sl1 or sl2; // -> sl3 = sl2
end;

–jeroen

3 Responses to “Delphi analog to C# ?? null-coalescing operator and Light Table like debugger evaluation”

  1. rvelthuis said

    The TObjectHelper thing is amazing. It also works on classes, and I already managed to do addition, or to write a helper that gives TStrings an in operator. It is simply a cool find.

    • jpluimers said

      It’s indeed one of the language additions I like a lot.

      • sglienke said

        It’s a feature by accident – I hope they will add it as an official feature. Some operators are harmless to introduce for classes also on non ARC. Also introducing operator overloads per helper is a good thing and should be supported officially rather than having to use some compiler glitch.

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: