Show: Delphi C++
Display Preferences

System.ObjAuto.ObjectInvoke

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function ObjectInvoke(Instance: TObject; MethodHeader: PMethodInfoHeader; const ParamIndexes: array of Integer; const Params: array of Variant): Variant;

C++

extern DELPHI_PACKAGE System::Variant __fastcall ObjectInvoke(System::TObject* Instance, PMethodInfoHeader MethodHeader, const int *ParamIndexes, const int ParamIndexes_High, const System::Variant *Params, const int Params_High);

Properties

Type Visibility Source Unit Parent
function public
System.ObjAuto.pas
System.ObjAuto.hpp
System.ObjAuto System.ObjAuto

Description

Dynamically invokes a method of an object.

Use ObjectInvoke to dynamically invoke a method of an object. This method must have sufficient type information.

Parameter Description
Instance The instance of the class to which the method belongs.
MethodHeader Represents type information of the method. It can be obtained with GetMethodInfo.
ParamIndexes An array of indexes of the parameters. This assumes that the indexes are 1 offset. The number of indexes do not need to match the number of parameters. The parameters left over are assumed to fill in the holes left by indexes. ParamIndexes are assumed to be in lexical order, not inverse lexical order like Params.
Params An array of type Variant and contains the parameters for the function invocation. The order of the parameters is assumed to be in inverse lexical order, last parameter first.


ObjectInvoke can invoke :

  • a 31 parameter method without a return type
  • a 30 or 31 parameter method with a return type

Some complex return type include String or record type needs hidden parameter. In this case, ObjectInvoke can invoke 30 parameters method.

ObjectInvoke does not resolve the overloaded methods. GetMethodInfo returns the first entry of overloaded method from method list. To select the proper method, you can use the System.Rtti.TRttiType.GetMethods function or other RTTI functions. Also ObjectInvoke does not support default parameter.


ObjectInvoke needs System.Rtti information to decide the number of parameters, the type of parameters and the return type. If the invoke method does not have enough System.Rtti information, ObjectInvoke raises an Exception class with SNoRTTIInfoType message. The following methods do not have System.Rtti information:

  • Safecall method
  • any parameters that have open array (for example: procedure foo( ary: array of integer ) )
  • any parameters that have value assigned enum type (for example: TFoo = (a, b, c = 100) )


For Windows 32 and OSX 32 only:

Because (Windows) OLE Variant does not support the 80-bit Extended type, the Variant type cannot keep an 80-bit / 10-byte Extended floating-point value. If a method has an Extended type parameter, or if a method returns an Extended type value, ObjectInvoke raises an EObjectInvokeExtendedTypeException class.

If the method's return type is an Extended type, ObjectInvoke invokes the method, captures the Extended value, and raises the EObjectInvokeExtendedTypeException with the original Extended value. The application can access Ext property to get the original return value.

The new RaiseExceptionForExtendedType flag is introduced into the System.ObjAuto unit. This flag is TRUE as default.

  • If this flag is True, ObjectInvoke has the same behavior as previous version. If any parameter is an Extended type, or if the return type is an Extended type, ObjectInvoke raises the exception.
  • If this flag is False, ObjectInvoke converts any Extended type parameter to a 64-bit Double type before invoking a method, and converts the Extended return value to Double.
Note: The Invoke method and the TValue type can handle the Extended type.

See Also

Code Examples

Personal tools
In Other Languages
Previous Versions
Assistance