[fpc-pascal] method pointers

memsom memsom at interalpha.co.uk
Tue Jan 17 11:33:53 CET 2006


>> In Delphi, the line
>>
>>         @UserDataEvent := pointer(FUserDataHandlers[I]);
>>
>> is common practice. What is the difference to FPC and the appropriate
>> workaround?

Forgive me for jumping in without reading the whole thread (Webmail is a
real PITA for this) but; No that is not completely correct. It does depend
on what you are doing. In Delphi, the _usual_ way to assign a method
pointer is as follows:

type TMyMethodPointer = procedure (const s; string) of object;

var
  mp: TMyMethodPointer;

...
  mp := AnInstance.CompatibleMethod;
...

However, for function pointers:

type TMyFuncPointer = procedure (const s; string);

var
  fp: TMyFuncPointer;

...
  fp := @CompatibleFunc;
...

The double dereference the poster uses above is not necessary. If
anything, the fact it works in Delphi is questionable.

M






More information about the fpc-pascal mailing list