To cybercake(数字蛋糕) 随便请你试试这段代码 var P : PPropInfo; begin P := GetPropInfo(Form1, 'ComponentCount'); if P<>NIL then Caption := 'AA'; P := GetPropInfo(Form1, 'Owner'); if P<>NIL then Caption := 'AA'; end; 你看一下你的窗口标题改成AA了吗?
To 楼上:对不起,你说的对。我曾经设置过TControl的Font(protected)属性。procedure ApplyFontToControl(AControl : TControl); var font : TFont; v : Cardinal; begin v := 0; if GetOrdPropertyValue(AControl, 'Font', v) then begin font := TFont(v); font.Name := 'XXX'; //... end; end;其中的GetOrdPropertyValue如下:function GetOrdPropertyValue(AInstance : TPersistent; APropertyName : String; var AValue : Cardinal) : Boolean; var prop : PPropInfo; begin Result := False; if AInstance = nil then Exit; prop := GetPropInfo(AInstance, APropertyName); Result := (prop <> nil) and (prop^.PropType^.Kind in [tkInteger, tkChar, tkEnumeration, tkClass, tkMethod, tkWChar, tkInterface]);
if Result then AValue := GetOrdProp(AInstance, APropertyName); end;虽然当时成功了,但回想一下是因为代入的参数实际上是有Font(published)属性的控件所致。所以因此看来,RTTI考虑的实际上是实参的类型信息,而不是形参……
不知你要表達什麼?>
不!各个域的都行。我的Langine(http://www.silentsea.net/candybox)里就有一个例子。
那好,
我请你写出用RTTI访问 Components[n]的程序来。
随便请你试试这段代码
var
P : PPropInfo;
begin
P := GetPropInfo(Form1, 'ComponentCount');
if P<>NIL then Caption := 'AA';
P := GetPropInfo(Form1, 'Owner');
if P<>NIL then Caption := 'AA';
end;
你看一下你的窗口标题改成AA了吗?
var
font : TFont;
v : Cardinal;
begin
v := 0;
if GetOrdPropertyValue(AControl, 'Font', v) then
begin
font := TFont(v);
font.Name := 'XXX';
//...
end;
end;其中的GetOrdPropertyValue如下:function GetOrdPropertyValue(AInstance : TPersistent;
APropertyName : String; var AValue : Cardinal) : Boolean;
var
prop : PPropInfo;
begin
Result := False;
if AInstance = nil then Exit; prop := GetPropInfo(AInstance, APropertyName);
Result := (prop <> nil)
and (prop^.PropType^.Kind in [tkInteger, tkChar, tkEnumeration, tkClass, tkMethod, tkWChar, tkInterface]);
if Result then
AValue := GetOrdProp(AInstance, APropertyName);
end;虽然当时成功了,但回想一下是因为代入的参数实际上是有Font(published)属性的控件所致。所以因此看来,RTTI考虑的实际上是实参的类型信息,而不是形参……
要想作其它事情,自己研究vmt表,在system。pas中有