참고하세요. 델파이 2009에서 동작하는 소스입니다.
<!--CodeS-->
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
type
TCountryLocale = (Croatia, Germany, Denmark, Norway, Sweden, USA);
TFolioType = (ftNotDefined, ftSales, ftInvoice, ftRoom, ftHall, ftTable);
TMainForm = class(TForm)
lbEnumTypes: TListBox;
MemoInfo: TMemo;
procedure FormCreate(Sender: TObject);
procedure lbEnumTypesClick(Sender: TObject);
end;
var
MainForm: TMainForm;
implementation
uses TypeInfo, Buttons;
{$R *.DFM}
function EnumToString(const TypeInfo: pTypeInfo; Ix: Integer): string;
begin
Result := GetEnumName(TypeInfo, ix);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
with lbEnumTypes.Items do
begin
AddObject('TCountryLocale', TypeInfo(TCountryLocale));
AddObject('TFolioType', TypeInfo(TFolioType)) ;
AddObject('Boolean', TypeInfo(Boolean)) ;
AddObject('TPenStyl', TypeInfo(TPenStyle)) ;
end;
lbEnumTypes.ItemIndex := 0;
lbEnumTypesClick(Self);
Caption := EnumToString(TypeInfo(TCountryLocale), Integer(Denmark));
end;
procedure TMainForm.lbEnumTypesClick(Sender: TObject);
var
OrdTypeInfo: PTypeInfo;
OrdTypeData: PTypeData;
TypeNameStr: string;
TypeKindStr: string;
MinVal, MaxVal: Integer;
ix: Integer;
begin
MemoInfo.Lines.Clear;
with lbEnumTypes 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 }
MainVal := OrdTypeData^.MinValue;
MaxVal := OrdTypeData^.MaxValue;
{- Add the information to the memo }
with MemoInfo.Lines do
begin
Add('Type Name: ' + TypeNameStr) ;
Add('Type Kind: ' + TypeKindStr);
Add('Min Val: ' + IntoToStr(MinVal));
Add('Max Val: ' + IntoToStr(MaxVal));
{- Show the values and names of the enumerated types }
if OrdTypeInfo^.Kind = tkEnumeration then
for ix := MinVal to MaxVal do
Add(Format(' Value %d Name: %s', [ix, GetEnumName(OrdTypeInfo, ix)]));
end;
end;
>파라미터로 넘어 온 컴포넌트의 속성을 검사해서 어떤 값이 들어 있는지 체크하려고 하는데요.
>TListBox나 TCombobox와 같이 object inspector에 안보이는 ItemIndex와 같은 값에 접근할 수 있는 방법이 있는지요?