[Overview][Constants][Types][Classes][Procedures and functions] | Reference for unit 'typinfo' (#rtl) |
Return value of a method property
Source position: line 0
function GetMethodProp( |
Instance: TObject; |
PropInfo: PPropInfo |
):TMethod; |
Instance: TObject; |
const PropName: String |
):TMethod; |
GetMethodProp returns the method the property described by PropInfo or with name Propname for object Instance. The return type TMethod is defined in the SysUtils unit as:
TMethod = packed record Code, Data: Pointer; end;
Data points to the instance of the class with the method Code.
No checking is done whether Instance is non-nil, or whether PropInfo describes a valid method property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
|
Set the value of a method property |
|
|
Get the value of an ordinal property |
|
|
Return the value of a string property. |
|
|
Return value of floating point property |
|
|
return value of an Int64 property |
|
|
Return the value of a set property. |
|
|
Return value of an object-type property. |
|
|
Return the value of an enumeration type property. |
program example6; { This program demonstrates the GetMethodProp function } {$mode objfpc} uses rttiobj,typinfo,sysutils; Type TNotifyObject = Class(TObject) Procedure Notification1(Sender : TObject); Procedure Notification2(Sender : TObject); end; Procedure TNotifyObject.Notification1(Sender : TObject); begin Write('Received notification 1 of object with class: '); Writeln(Sender.ClassName); end; Procedure TNotifyObject.Notification2(Sender : TObject); begin Write('Received notification 2 of object with class: '); Writeln(Sender.ClassName); end; Var O : TMyTestObject; PI : PPropInfo; NO : TNotifyObject; M : TMethod; Procedure PrintMethod (Const M : TMethod); begin If (M.Data=Pointer(NO)) Then If (M.Code=Pointer(@TNotifyObject.Notification1)) then Writeln('Notification1') else If (M.Code=Pointer(@TNotifyObject.Notification2)) then Writeln('Notification2') else begin Write('Unknown method adress (data:'); Write(hexStr(Longint(M.data),8)); Writeln(',code:',hexstr(Longint(M.Code),8),')'); end; end; begin O:=TMyTestObject.Create; NO:=TNotifyObject.Create; O.NotifyEvent:=@NO.Notification1; PI:=GetPropInfo(O,'NotifyEvent'); Writeln('Method property : '); Write('Notifying : '); O.Notify; Write('Get (name) : '); M:=GetMethodProp(O,'NotifyEvent'); PrintMethod(M); Write('Notifying : '); O.Notify; Write('Get (propinfo) : '); M:=GetMethodProp(O,PI); PrintMethod(M); M:=TMethod(@NO.Notification2); SetMethodProp(O,'NotifyEvent',M); Write('Set (name,Notification2) : '); M:=GetMethodProp(O,PI); PrintMethod(M); Write('Notifying : '); O.Notify; Write('Set (propinfo,Notification1) : '); M:=TMethod(@NO.Notification1); SetMethodProp(O,PI,M); M:=GetMethodProp(O,PI); PrintMethod(M); Write('Notifying : '); O.Notify; O.Free; end.
No notes exist for this page yet.