본문 바로가기

Delphi/꿀팁

Rtti로 Enum타입 목록 가져오기

uses
  .., System.Rtti, System.TypeInfo;

type
  TDeveopistType = (dtTest1, dtTest2, dtTest3, dtTest4, dtTest5);
  
var
  I: Integer;
  FieldType: TRttiType;
  OrdinaryType: TRttiOrdinalType;
  Name: string;
begin
  FieldType := TRttiContext.Create.GetType(TypeInfo(TDeveopistType));
  OrdinaryType := FieldType.AsOrdinal;
  
  for I := OrdinaryType.MinValue to OrdinaryType.MaxValue do begin
    Name := GetEnumName(FieldType.Handle, I);
    
    ShowMessage(Name);
  end;
end;
반응형