|
TProperty class
TProperty class is a class that allows to access to the property of some object. Any information can be access with extremal simplicity:
procedure TForm1.FormClick(Sender: TObject);
var
P: TProperty;
begin
with TPropertyList.Create(nil) do
try
Instance:=Self;
Root:=Self;
// retreiving the font name
P:=FindProperty('Font.Name');
if Assigned(P) then ShowMessage(P.AsString);
// changing the font style - different ways
P:=FindProperty('Font.Style');
if Assigned(P) then
begin
// setting as integer using set bit masks
P.AsInteger:=Integer(1 shl Integer(fsItalic));
// setting as string
P.AsString:='[fsBold,fsItalic,fsUnderline]';
end;
// direct setting using subproperty
P:=FindProperty('Font.Style.fsBold');
if Assigned(P) then P.AsBoolean:=False;
// changing the font using direct access to the Font object
P:=FindProperty('Font');
with (P.AsObject as TFont) do
begin
Style:=[];
Color:=clRed;
end;
// restoring the font color
P:=FindProperty('Font.Color');
if Assigned(P) then P.AsInteger:=clWindowText;
// the string value can be used too:
// if Assigned(P) then P.AsString:='clWindowText';
// getting the method declaration
P:=FindProperty('OnDragOver');
if Assigned(P) then ShowMessage(P.MethodDeclaration);
finally
Free;
end;
end;
|