



Definição dos tipos
1 2 3 4 | type TType = (mtMenuFaturamento, mtMenuRelatorios); const StrType: array [TType] of string = ('MENU FATURAMENTO', 'MENU RELATÓRIOS'); |
USANDO RTTI
1 2 3 4 5 6 7 8 9 10 11 12 | uses System.Rtti; ... procedure TForm1.BtnComRTTIClick(Sender: TObject); var S: string; I: Integer; begin I := Edit1.Value; S := TRttiEnumerationType.GetName(TType(I)); ShowMessage('Tipo: ' + S + sLineBreak + 'Str : ' + StrType[TType(I)]); end; |
SEM USAR RTTI
1 2 3 4 5 6 7 8 9 10 11 12 13 | uses System.TypInfo ... procedure TForm1.BtnSemRTTIClick(Sender: TObject); var S: string; I: Integer; begin I := Edit1.Value; S := GetEnumName(TypeInfo(TType), I); ShowMessage( 'Tipo: ' + S + sLineBreak + 'Str : ' + StrType[TType(GetEnumValue(TypeInfo(TType),S))]); end; |
Para facilitar o entendimento, disponibilizamos um vídeo com a aplicação da dica.
Dúvidas ou sugestões, deixe o seu comentário.