Listar as propriedades de um objeto |
Top Previous Next |
|
Definição
Tenho um objeto, gostaria de listar todas as propriedades deste objeto e seus tipos sem necessariamente saber quais são.
Fonte unit UnitX;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, TypInfo, Dialogs, StdCtrls;
type TBesta = class(TObject) private FAsno: Boolean; FMula: Integer; FAnta: string; published property Anta: string read FAnta write FAnta; property Mula: Integer read FMula write FMula; property Asno: Boolean read FAsno write FAsno; end;
TForm9 = class(TForm) Button1: TButton; ListBox1: TListBox; procedure Button1Click(Sender: TObject); end;
var Form9: TForm9;
implementation
{$R *.dfm}
procedure TForm9.Button1Click(Sender: TObject); var Count, I: Integer; List : TPropList; Besta : TBesta; Info : PPropInfo; begin Besta := TBesta.Create; Count := GetPropList(TypeInfo(TBesta), tkProperties, @List);
for I := 0 to Pred(Count) do begin Info := GetPropInfo(TypeInfo(TBesta), List[I]^.Name); Listbox1.Items.Add(List[I]^.Name + ' : ' + Info^.PropType^.Name); end;
Besta.Free; end;
end.
Saída na ListBox em tela
|