简体   繁体   English

我如何填写德尔福集?

[英]How do I fill a Delphi set?

If I have a type defined as a set of an enumerated type, it's easy to create an empty set with [], but how do I create a full set? 如果我将类型定义为枚举类型的集合 ,则使用[]创建空集很容易,但如何创建完整集?

EDIT: Yeah, the obvious solution is to use a for loop. 编辑:是的,显而易见的解决方案是使用for循环。 That's also a really bad solution if there's another way. 如果有另一种方式,这也是一个非常糟糕的解决方案。 Does anyone know of a way that'll work in constant time? 有谁知道一种在恒定时间内工作的方式?

Low() and High() are "compiler magic" functions that can be evaluated at compile time. Low()和High()是可以在编译时评估的“编译魔术”函数。 This allows their use in constant declarations like the following: 这允许它们在常量声明中使用,如下所示:

var
  MySet : TBorderIcons;
  MySet2 : TBorderIcons;
const
  AllIcons : TBorderIcons = [Low(TBorderIcon)..High(TBorderIcon)];
begin
  MySet := [Low(TBorderIcon)..High(TBorderIcon)];
  MySet2 := AllIcons;
end;

Per Barry的建议:

FillChar(VarSet, SizeOf(VarSet), $FF);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM