{Delphi Example}
//記得在Uses中引用TypInfo
TColor =(red,blue,green,yellow,white,black);
var
piType:PTypeInfo;
i:Integer;
clColor:TColor;
s:String;
begin
piType:= TypeInfo(TColor);
with GetTypeData(piType)^ do
begin
for i := MinValue to MaxValue do
begin
s := GetEnumName(piType,i);
ShowMessage(s);
{
case TColor(GetEnumValue(piType,s)) of //這樣顯得有點多余,但是某種情況下還得用這種。
// case TColor(i) of
red : ShowMessage('red');
blue: ShowMessage('blue');
green: ShowMessage('green');
yellow : ShowMessage('yellow');
white: ShowMessage('white');
black: ShowMessage('black');
end; }
end;
end;