список всех свойств какого-либо компонента

17:55
Starter (23.03.05 08:45)
Как можно (можно ли?) получить список всех свойств какого-либо компонента? Например, вывести в TreeView дерево свойств компонента TPanel со всеми вложениями?

*******************************************

Юрий Зотов © (23.03.05 12:59) [5]
> Starter

Вот, нашел в загашнике, писал этот пример когда-то.

type
TfrmPropViewer = class(TForm)
cbComponents: TComboBox;
tvProps: TTreeView;
procedure FormCreate(Sender: TObject);
procedure cbComponentsChange(Sender: TObject);
private
procedure ShowObjectProps(ObjectNode: TTreeNode);
end;
 
procedure TfrmPropViewer.ShowObjectProps(ObjectNode: TTreeNode);
var
Obj: TObject;
PropCount, i: integer;
PropList: PPropList;
Node: TTreeNode;
HasIdent: TIntToIdent;
PropValue: string;
begin
Obj := TObject(ObjectNode.Data);
if Obj <> nil then
begin
PropCount := GetPropList(Obj.ClassInfo, tkProperties, nil);
if PropCount > 0 then
begin
GetMem(PropList, PropCount * SizeOf(PPropInfo));
try
GetPropList(Obj.ClassInfo, tkProperties, PropList);
for i := 0 to PropCount - 1 do
begin
Node := tvProps.Items.AddChild(ObjectNode, PropList^[i]^.Name);
if PropList^[i]^.PropType^^.Kind = tkClass then
begin
Node.Data := GetObjectProp(Obj, PropList^[i]);
if TObject(Node.Data) is TPersistent then
Node.Text := Format('%s (%s)', [Node.Text, TPersistent(Node.Data).GetNamePath]);
ShowObjectProps(Node)
end
else
begin
HasIdent := FindIntToIdent(PropList^[i]^.PropType^);
if (@HasIdent = nil) or not HasIdent(GetOrdProp(Obj, PropList^[i]), PropValue) then
PropValue := VarToStr(GetPropValue(Obj, Node.Text));
if PropList^[i]^.PropType^^.Kind = tkSet then
PropValue := Format('[%s]', [StringReplace(PropValue, ',', ', ', [rfReplaceAll])]);
Node.Text := Format('%s = %s', [Node.Text, PropValue])
end
end
finally
FreeMem(PropList)
end
end
end
end;
 
procedure TfrmPropViewer.FormCreate(Sender: TObject);
 
procedure AddComponent(C: TComponent);
begin
cbComponents.Items.AddObject(Format('%s: %s', [C.Name, C.ClassName]), C)
end;
 
var
i: integer;
begin
cbComponents.Align := alTop;
tvProps.Align := alClient;
AddComponent(Self);
for i := 0 to ComponentCount - 1 do
AddComponent(Components[i]);
cbComponents.ItemIndex := 0;
cbComponentsChange(nil)
end;
 
procedure TfrmPropViewer.cbComponentsChange(Sender: TObject);
var
C: TComponent;
begin
with tvProps.Items do
begin
BeginUpdate;
try
Clear;
with cbComponents, Items do
C := TComponent(Objects[ItemIndex]);
ShowObjectProps(tvProps.Items.AddObjectFirst(nil, C.Name, C));
tvProps.Items.GetFirstNode.Expand(False)
finally
EndUpdate
end
end
end;

А это файл DFM:

object frmPropViewer: TfrmPropViewer
Left = 337
Top = 149
Width = 415
Height = 467
ActiveControl = cbComponents
Caption = 'Property Viewer'
Color = clBtnFace
Constraints.MinHeight = 64
Constraints.MinWidth = 118
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 120
TextHeight = 16
object cbComponents: TComboBox
Left = 0
Top = 0
Width = 319
Height = 24
Style = csDropDownList
ItemHeight = 16
TabOrder = 0
OnChange = cbComponentsChange
end
object tvProps: TTreeView
Left = 0
Top = 25
Width = 319
Height = 414
Indent = 19
ReadOnly = True
TabOrder = 1
end
end
 
 


http://delphimaster.ru/cgi-bin/forum.pl?id=1111556713&n=0