uses TypInfo; // 追加
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
s:string;
obj:TComponent;
V:Variant; // 追加
begin
for i := 0 to Form1.ComponentCount - 1 do begin
obj := Form1.Components[i];
s := obj.Name;
listbox1.Items.Append(s);
//
{
if obj is TButton then begin
s := inttostr(TButton(obj).top);
listbox1.Items.Append(s);
end;
//
if obj is TPanel then begin
s := inttostr(TPanel(obj).top);
listbox1.Items.Append(s);
end;
//
if obj is TStringGrid then begin
s := inttostr(TStringGrid(obj).top);
listbox1.Items.Append(s);
end;
}
try
V := GetPropValue(obj, 'Top');
listbox1.Items.Append(V);
except
on EPropertyError do listbox1.Items.Append('No property');
end;
end;
end;
こんなかんじでいいのかな?
|