|
Access internal data of RTTI (Runtime Type Information)
TProperty has properties allowing to access all RTTI-related technical information through the properties appropriate to RTTI's PropInfo data (PropType, GetProc, SetProc, StoredProc, Index, Default, NameIndex and Name). The following example shows the NameIndex (sequental number of the property in the class declaration).
procedure TForm1.FormClick(Sender: TObject);
var
P: TProperty;
begin
with TPropertyList.Create(nil) do
try
Instance:=Self;
Root:=Self;
P:=FindProperty('Caption');
if Assigned(P) then ShowMessage(IntToStr(Integer(P.NameIndex)));
finally
Free;
end;
end;
Most useful property from the PropInfo data is Name that contains the property name. The following code fills the memo with the names of all properties of the form.
procedure TForm1.FormClick(Sender: TObject);
var
i: Integer;
S: string;
begin
with TPropertyList.Create(nil) do
try
Instance:=Self;
Root:=Self;
S:='';
for i:=0 to Pred(Count) do S:=S+Properties[i].Name+#13;
Memo1.Lines.Text:=S;
finally
Free;
end;
end;
|