6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Delphi] Delphi 13 Florence で追加された演算子

Last updated at Posted at 2025-10-01

Delphi 13 Florence

Delphi 13 Florence が 2025/9/12 にリリースされました。

新しい演算子が3つ追加されたのでご紹介いたします。

if 条件演算子(三項演算子・if式)

今回のリリース前から話題になっていた if 条件演算子です。

一般的には「三項演算子」や「if式」という名前で知られています。
↓こんな感じで使えます。

if条件演算子
var Foo := if Str.IsEmpty then '文字列は空です' else Str;

is not 演算子

これはシンタックスシュガーの一種です。

今までは↓こう書いていました。
is 演算子の否定には括弧を用いる必要がありました。

従来
if not (Sender is TEdit) then 
  Result := 'Sender ≠ TEdit';

この面倒な括弧が要らなくなるように新設されたのが is not 演算子です。

is not 版
if Sender is not TEdit then 
  Result := 'Sender ≠ TEdit';

not in 演算子

こちらも is not 演算子と同じで、シンタックスシュガーの一種です。

従来
if not (Foo in [0.. 9]) then
  Result := 'Foo > 9';

is not 同様、括弧が要らなくなりました。

not in 版
if Foo not in [0.. 9] then
  Result := 'Foo > 9';

NameOf ビルトイン関数

演算子ではないのですが、これも興味深い関数なので紹介しておきます。
NameOf は引数に渡された識別子の文字列をそのまま返すだけです。
ログを吐くときやデバッグ時に便利そうです。

type
  TTest = (Foo, Bar, Baz);

begin
  var Test := TTest.Foo;

  // "Test" を表示
  Writeln(NameOf(Test)); 

  // "Foo" を表示
  Writeln(Foo);

  // SCOPEDENUMS を ON にしてもスコープ付き列挙値は書けない
  Writeln(TTest.Foo); // エラー
end.

最後に

コンパイラ・言語機能の拡張という意味では、他にも

  • noreturn 指令
  • \$PUSHOPT / $POPOPT 指令
  • ジェネリック型の制約に interface, unmanaged を追加
  • カスタム管理レコードの Initialize / Finalize に暗黙の Self を追加

があります。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?