lamas
lamas

Reputation: 4598

Delphi pointer syntax

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

Upvotes: 2

Views: 421

Answers (2)

Ljubomir Đokić
Ljubomir Đokić

Reputation: 426

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

Upvotes: 0

Jens Mühlenhoff
Jens Mühlenhoff

Reputation: 14873

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

Upvotes: 9

Related Questions