代码之家  ›  专栏  ›  技术社区  ›  lamas

Delphi指针语法

  •  2
  • lamas  · 技术社区  · 14 年前

    我必须传递一个这种类型的参数 Pointer 从外部DLL创建函数。

    • 我是否也可以将指向类成员函数的指针传递给外部函数,或者这不起作用?
    2 回复  |  直到 14 年前
        1
  •  9
  •   Jens Mühlenhoff    14 年前

    只是使用 @MyProcedure

    注意它必须有正确的调用约定(可能是 stdcall ).

    SELF 参数。

    class static 方法的行为与通常的过程/函数类似。

    http://docwiki.embarcadero.com/RADStudio/en/Methods

        2
  •  0
  •   Ljubomir Đokić    14 年前

    如果过程(或函数)是方法,则创建此类型

    type
      TMyProc = Procedure(x:Integer;y:Integer) of Object;
    

    type
      TMyProc = Procedure(x:Integer;y:Integer);
    

    如果程序是独立的。

    //Some class method
    Procedure TfrmMain.Add(x:Integer;y:Integer);
    begin
      ...
    end;
    
    //Another class method that uses procedure as parameter
    procedure Name(proc : TMyProc);
    begin
      ...
    end;
    
    //Call with:
    
    Name(Add);