Вывести информацию о возможных значениях свойств
Автор: Xavier Pacheco
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TMainForm = class(TForm)
lbSamps: TListBox;
memInfo: TMemo;
procedure FormCreate(Sender: TObject);
procedure lbSampsClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses TypInfo, Buttons;
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
// Add some example enumerated types
with lbSamps.Items do
begin
AddObject('TBorderIcons', TypeInfo(TBorderIcons));
AddObject('TGridOptions', TypeInfo(TGridOptions));
end;
end;
procedure GetTypeInfoForOrdinal(AOrdTypeInfo: PTypeInfo; AStrings: TStrings);
var
// OrdTypeInfo: PTypeInfo;
OrdTypeData: PTypeData;
TypeNameStr: string;
TypeKindStr: string;
MinVal, MaxVal: Integer;
i: integer;
begin
// Get the TTypeData pointer
OrdTypeData := GetTypeData(AOrdTypeInfo);
// Get the type name string
TypeNameStr := AOrdTypeInfo.Name;
// Get the type kind string
TypeKindStr := GetEnumName(TypeInfo(TTypeKind), Integer(AOrdTypeInfo^.Kind));
// Get the minimum and maximum values for the type
MinVal := OrdTypeData^.MinValue;
MaxVal := OrdTypeData^.MaxValue;
// Add the information to the memo
with AStrings do
begin
Add('Type Name: ' + TypeNameStr);
Add('Type Kind: ' + TypeKindStr);
// Call this function recursively to show the enumeration
// values for this set type.
if AOrdTypeInfo^.Kind = tkSet then
begin
Add('==========');
Add('');
GetTypeInfoForOrdinal(OrdTypeData^.CompType^, AStrings);
end;
// Show the values and names of the enumerated types belonging to the
// set.
if AOrdTypeInfo^.Kind = tkEnumeration then
begin
Add('Min Val: ' + IntToStr(MinVal));
Add('Max Val: ' + IntToStr(MaxVal));
for i := MinVal to MaxVal do
Add(Format(' Value: %d Name: %s', [i, GetEnumName(AOrdTypeInfo,
i)]));
end;
end;
end;
procedure TMainForm.lbSampsClick(Sender: TObject);
begin
memInfo.Lines.Clear;
with lbSamps do
GetTypeInfoForOrdinal(PTypeInfo(Items.Objects[ItemIndex]), memInfo.Lines);
end;
end.
|