Получить информацию о целых типах
Автор: Xavier Pacheco
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
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;
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
with lbSamps.Items do
begin
AddObject('Word', TypeInfo(Word));
AddObject('Integer', TypeInfo(Integer));
AddObject('Byte', TypeInfo(Byte));
end;
end;
procedure TMainForm.lbSampsClick(Sender: TObject);
var
OrdTypeInfo: PTypeInfo;
OrdTypeData: PTypeData;
TypeNameStr: string;
TypeKindStr: string;
MinVal, MaxVal: 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));
end;
end;
end;
end.
|