I found a solution that works: imp_implementationWithBlock
procedure performFetchWithCompletionHandler(self : id; _cmd : SEL; application: PUIApplication; handler : id );
// Changed the handler for entering id (pointer)
const libobjc = '/usr/lib/libobjc.dylib'; {$IF NOT DECLARED(_PU)} const {$IFDEF UNDERSCOREIMPORTNAME} _PU = '_'; {$ELSE} _PU = ''; {$ENDIF} {$EXTERNALSYM _PU} {$ENDIF} function imp_implementationWithBlock( block :id ) : IMP; cdecl; external libobjc name _PU + 'imp_implementationWithBlock'; function imp_removeBlock( anImp : IMP ) : integer; cdecl; external libobjc name _PU + 'imp_removeBlock';
// Added links to imp_implementationWithBlock and imp_removeBlock from libobjc
type IMP = function( self : id; cmd : SEL; Param1 : NSUInteger ) : id; cdecl;
// The declared IMP type as function c, corresponding to the function pointer returned by imp_implementationWithBlock in this particular case with one NSUInteger parameter.
procedure performFetchWithCompletionHandler(self : id; _cmd : SEL; application: PUIApplication; handler : id ); var ahandlerimp : IMP; begin .... //Code to perform fetch ahandlerimp := imp_implementationWithBlock( handler ); //Create c function for block ahandlerimp(self,_cmd,FetchResult ); //Call c function, _cmd is ignored imp_removeBlock(ahandlerimp); //Remove the c function created two lines up end;
source share