2010-09-06 78 views
2

我不得不類型Pointer的參數從外部DLL傳遞給函數。的Delphi指針語法

  • 如何創建一個指向我可以傳遞給該函數的過程的指針?
  • 我能否也傳遞一個指針類成員函數的外部函數,或將不是工作?

回答

9

只需使用@MyProcedure即可。

要注意的是它必須有正確的調用約定(可能stdcall)。

您通常不能使用成員函數,因爲它有一個隱藏的SELF參數。

class一個方法static作用就像通常的程序/功能雖然。

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

+0

+1,也包括鏈接到文檔 – 2010-09-06 18:45:55

0

創建這種類型的,如果程序(或功能)是方法

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);