System.TObject.MethodAddress

From RAD Studio VCL Reference
Jump to: navigation, search

Contents

Delphi Information

From System.pas

	class function MethodAddress(const Name: ShortString): Pointer; overload;
 
	class function MethodAddress(const Name: string): Pointer; overload;


Unit: System

Type: method

Visibility: public

Member Of: TObject

C++ Information

From System.hpp

	__classmethod void * __fastcall MethodAddress(const System::SmallString<255> & Name);
 
	__classmethod void * __fastcall MethodAddress(System::UnicodeString Name);


Unit: System

Type: method

Visibility: public

Member Of: TObject

Description

Returns the address of a class method by name.


There are situations when it is useful to invoke an object method without hard coding the method name in advance. Call MethodAddress to dynamically retrieve the address of such a method by specifying the method Name as a string.

An easy way to invoke the method is to define a procedure or function data type, such as:

type TProc = procedure of object;

Assign the object name and the MethodAddress method to a TMethod variable, such as:

MethodVar.Data := Pointer(ObjectInstanceName);

MethodVar.Code := ObjectInstanceName.MethodAddress('MethodNameString');

Pass this in a call to a variable of the procedure or function type:

Proc := TProc(MethodVar);

Proc;

See Also

Personal tools
Translations
Newest Version