用于下涵數:(注:加入typinfo單元) function GetPropPointer(obj: TObject; propName: string): PSingle; var Getter: Longint; PropInfo :PPropInfo ; begin Result := nil ; if obj = nil then Exit ; PropInfo:= GetPropInfo(obj,PropName) ; if PropInfo=nil then Exit ; if PropInfo^.PropType^^.Kind<> tkFloat then Exit ; Getter := Longint(PropInfo^.GetProc); Result := Pointer(Integer(obj) + (Getter and $00FFFFFF)); end;
没有必要.不太显示而且..................................
property只是封装了类似.net的getter和setter方法,实际编译的时候,都会变成property所指向的read的函数或者字段.属性只是在设计时面向用户的
况且如果
property myProperty:single;read getMyProp() write setMyProp();那你的myProperty指的是getmyprop还是setmyprop呢?????这样就出现二义性了.所以就算按照楼上说的,也不过是得到的getter函数的返回值的指针,而不是属性的指针.
function GetPropPointer(obj: TObject; propName: string): PSingle;
var
Getter: Longint;
PropInfo :PPropInfo ;
begin
Result := nil ;
if obj = nil then Exit ;
PropInfo:= GetPropInfo(obj,PropName) ;
if PropInfo=nil then Exit ;
if PropInfo^.PropType^^.Kind<> tkFloat then Exit ;
Getter := Longint(PropInfo^.GetProc);
Result := Pointer(Integer(obj) + (Getter and $00FFFFFF));
end;