ObjectInvoke (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example illustrates the usage of the GetMethodInfo and ObjectInvoke functions.

Code

program Project_ObjectInvoke;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ObjAuto;

{$METHODINFO ON}

type
  TSquirrel = class
  public
    function Jump(Height: Integer): Integer;
  end;

function TSquirrel.Jump(Height: Integer): Integer;
begin
  Result := 10 * Height;
end;

var
  Squirrel: TSquirrel;
  JumpInfo: PMethodInfoHeader;
  Result: Variant;

begin
  Squirrel := TSquirrel.Create;

  JumpInfo := GetMethodInfo(Squirrel, 'Jump');
  Writeln(JumpInfo^.Name);

  Result := ObjectInvoke(Squirrel, JumpInfo, [1], [2]);
  Writeln(Result);
end.

Console Output

Jump
20

Uses

See Also