TypeInfo Function
The TypeInfo
function returns a pointer to a
type’s runtime type information. The pointer is actually a
PTypeInfo
pointer, which is a pointer to a
TTypeInfo
record. These types are declared in the
TypInfo
unit.
See Chapter 3 for more information about runtime type information.
// Convert a set to a string representation, e.g.,
// '[fsBold,fsItalic]'.
function SetToString(Info: PTypeInfo; const Value): string;
var
I: Integer;
Data: PTypeData; // set's type data
EnumInfo: PTypeInfo; // set's base type info
EnumData: PTypeData; // set's base type data
begin
if Info.Kind <> tkSet then
Result := ''
else
begin
Data := GetTypeData(Info);
EnumInfo := Data^.CompType^;
EnumData := GetTypeData(EnumInfo);
Assert(EnumInfo.Kind in [tkEnumeration,tkInteger]);
Result := '[';
for I := EnumData.MinValue to EnumData.MaxValue do
if I in TIntegerSet(Value) then
begin
// The element is in the set, so add its name to the string.
if Length(Result) > 1 then
Result := Result + ','; // Separate items with commas.
Result := Result + GetEnumName(EnumInfo, I);
end;
Result := Result + ']';
end;
end;
...
S := SetToString(TypeInfo(TFontStyles), Control.Font.Style);