如何获取 Delphi 集类型变量的互补值?

How to get the complementary values for a Delphi sets type variable?

从集合类型变量开始,如 TAnchors:

  TAnchorKind = (akLeft, akTop, akRight, akBottom);
  TAnchors = set of TAnchorKind;

我正在尝试获取互补值。

var
  Tmp : TAnchors;
begin
  Tmp := [akLeft];
   ...
end;

我希望获得 TAnchors 的所有值,这些值不在 Tmp 变量中。

例如,从 [akLeft] 开始,我希望得到 [akTop, akRight, akBottom]

我试过使用 not 运算符,但它似乎不适用于 Sets types

集合运算符列在documentation中。 not 运算符未在此处列出,这就是它不能用于集合的原因。但是,您正在寻找差异运算符 -。计算包含所有成员的集合与您的集合之间的差异:

[Low(TAnchorKind)..High(TAnchorKind)] - Anchors