遍历集合类型
代码
通过 for-in 循环遍历
uses System.TypInfo;
procedure TForm1.Button1Click(Sender: TObject);
var
vAnchors: TAnchors;
vAnchor: TAnchorKind;
begin
vAnchors := [akLeft, akTop, akBottom];
for vAnchor in vAnchors do
begin
Memo1.Lines.Add(GetEnumName(TypeInfo(TAnchorKind), Ord(vAnchor)));
end;
end;
通过 for 循环遍历
uses System.TypInfo;
procedure TForm1.Button2Click(Sender: TObject);
var
vAnchors: TAnchors;
vAnchor: TAnchorKind;
begin
vAnchors := [akLeft, akTop, akBottom];
for vAnchor := Low(TAnchorKind) to High(TAnchorKind) do
begin
if vAnchor in vAnchors then
begin
Memo1.Lines.Add(GetEnumName(TypeInfo(TAnchorKind), Ord(vAnchor)));
end;
end;
end;