列出枚举类型所有值的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, TypInfo, StdCtrls;
type
TEnum = (One, Two, Three, Four, Five);
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
t: PTypeInfo;
d: PTypeData;
i: Integer;
begin
t:=TypeInfo(TEnum);
d:=GetTypeData(t);
for i:=0 to d.MaxValue do
ListBox1.Items.Add(GetEnumName(TypeInfo(TEnum), i))
end;
end.