定义的枚举类型我只能取出他的顺序值,就是1,2,3,4什么的,我怎么才能取出他的
字符值,就是定义时写的,请指教
procedure TMainForm.lbSampsClick(Sender: TObject);
var
OrdTypeInfo: PTypeInfo;
OrdTypeData: PTypeData;
TypeNameStr: String;
TypeKindStr: String;
MinVal, MaxVal: Integer;
i: integer;
begin
memInfo.Lines.Clear;
with lbSamps do
begin
// Get the TTypeInfo pointer
OrdTypeInfo := PTypeInfo(Items.Objects[ItemIndex]);
// Get the TTypeData pointer
OrdTypeData := GetTypeData(OrdTypeInfo);
// Get the type name string
TypeNameStr := OrdTypeInfo.Name;
// Get the type kind string
TypeKindStr := GetEnumName(TypeInfo(TTypeKind),
Integer(OrdTypeInfo^.Kind));
// Get the minimum and maximum values for the type
MinVal := OrdTypeData^.MinValue;
MaxVal := OrdTypeData^.MaxValue;
// Add the information to the memo
with memInfo.Lines do
begin
Add('Type Name: '+TypeNameStr);
Add('Type Kind: '+TypeKindStr);
Add('Min Val: '+IntToStr(MinVal));
Add('Max Val: '+IntToStr(MaxVal));
// Show the values and names of the enumerated types
if OrdTypeInfo^.Kind = tkEnumeration then
for i := MinVal to MaxVal do
Add(Format(' Value: %d Name: %s', [i, GetEnumName(OrdTypeInfo,
i)]));
end;
end;
end;