开发者

Delphi pointer syntax

开发者 https://www.devze.com 2023-01-15 12:53 出处:网络
I have to pass an argument of the type Pointer to a function from an external DLL. How do I create a pointer to a procedure which I can then pass to the function?

I have to pass an argument of the type Pointer to a function from an external DLL.

  • How do I create a pointer to a procedure which I can then pass to the function?
  • Can I also pass a pointer to a class member function to the external functio开发者_运维问答n, or will that not work?


Just use @MyProcedure for that.

Beware that it has to have the right calling convention (probably stdcall).

You usually can't use a member function, because it has a hidden SELF parameter.

A class static method acts like a usual procedure/function though.

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


Create this type if procedure (or function) is method

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

or this

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

if procedure is stand alone.

Usage:

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

精彩评论

暂无评论...
验证码 换一张
取 消