Цитата(LECIAN @ 31.7.2007, 21:59 ) | | Возможно ли получить указатель на свойство Value зная его строковое имя ('Value')? |
Указатель на сво-во... может PPropinfo тебе нужен? Тогда так:
| Код | unit Unit10;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, TypInfo;
const C_PROP_VALUE: string = 'test';
type TForm10 = class(TForm) procedure FormCreate(Sender: TObject); private FTest: string; { Private declarations } published property Test: string read FTest write FTest; end;
var Form10: TForm10;
implementation
{$R *.dfm}
function GetPropInfoByValue(AObject: TObject; AValue: Variant): PPropInfo; var lpPropList: PPropList; lCount: Integer; i: Integer; lpPropInfo: PPropInfo; lValue: Variant; begin Result := nil; lCount := GetPropList(AObject, lpPropList); if (lCount > 0) and Assigned(lpPropList) then begin for i := 0 to lCount - 1 do begin lpPropInfo := lpPropList^[i]; if Assigned(lpPropInfo) then begin lValue := GetPropValue(AObject, lpPropInfo); if (not VarIsNull(lValue)) and (VarType(lValue) = VarType(AValue)) then if lValue = AValue then begin Result := lpPropInfo; Break; end; end; end; end; end;
procedure TForm10.FormCreate(Sender: TObject); var lpPropInfo: PPropInfo; begin Test := C_PROP_VALUE; lpPropInfo := GetPropInfoByValue(Self, C_PROP_VALUE); if Assigned(lpPropInfo) then ShowMessage(lpPropInfo^.Name); end;
|
|