Author Topic: Header translation question (callbacks)  (Read 3777 times)


  • Hero Member
  • *****
  • Posts: 502
Header translation question (callbacks)
« on: March 05, 2015, 12:36:49 pm »
The header parser that processes the whole frameworks sadly isn't able to parse single files.
Even when reconstructing a ".framework/Headers" structure.
I've written two header translations myself, but am at a loss currently where it comes to callbacks:

Code: [Select]
#import <Foundation/Foundation.h>
@interface LLInstalledApps : NSObject
+ (NSArray *) runningApps;
- (BOOL) appsInstalledWithScheme:(NSString *)applicationScheme;
+ (NSDictionary *) appsInstalledWithSchemes:(NSArray *)applicationSchemes;
+ (NSDictionary* ) appsInstalledWithSchemes:(NSArray *)applicationSchemes withProgressCallback:(void (^)(id))callbackBlock;
+ (NSArray* ) appsInstalledWithSchemes:(NSArray *)applicationSchemes withProgressCallback:(void (^)(id))callbackBlock maxSize:(int) maxSize;

My interpretation was:
Code: [Select]
   TLLInstalledAppsCallback = procedure(callbackBlock: NSNumber); cdecl;

   LLInstalledApps = objcclass external (NSObject)
      class function runningApps: NSArray; message 'runningApps';
      function appsInstalledWithScheme(AScheme: NSString): boolean; message 'appsInstalledWithScheme:';
      class function appsInstalledWithSchemes(ASchemes: NSArray): NSDictionary; message 'appsInstalledWithSchemes:';
      class function appsInstalledWithSchemes_withProgressCallback(ASchemes: NSArray; AProgressCallback: TLLInstalledAppsCallback): NSDictionary; message 'appsInstalledWithSchemes:withProgressCallback:';
      class function appsInstalledWithSchemes_withProgressCallback_maxSize(ASchemes: NSArray; AProgressCallback: TLLInstalledAppsCallback; AMaxSize: integer): NSArray; message 'appsInstalledWithSchemes:withProgressCallback:maxSize:';
// ...
procedure schemesCallback(callbackBlock: NSNumber); cdecl;
   dbg('Hello World');
But these callbacks lead to an EXC_BAD_ACCESS.

Any help how to:
1. properly implement the callback here, or
2. get the header parser to work on single files correctly

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 710
Re: Header translation question (callbacks)
« Reply #1 on: March 05, 2015, 12:42:07 pm »
The correct terminology for those callback parameters is "block" or "C block". The Objective-C header translator does not support them, because until recently, FPC itself did not yet support blocks. However, there is now limited support for them in trunk, see

The translation of the type "(void (^)(id))" in Pascal is

  tidblock = reference to procedure(obj: id); cdecl;


  • Hero Member
  • *****
  • Posts: 502
Re: Header translation question (callbacks)
« Reply #2 on: March 06, 2015, 11:11:17 am »
Wow! Can't say how happy I'm about FreePascal every day :)

Still remember times when I filed bugs with CodeGear/Emba and either was told it was "by design" or ignored until years later it might happen.

How awesome is this instead?

Created the whole environment with cross compilers again, updated the project to use the new compilers, and now it compiles these blocks, and they work.

Many thanks for pointing this new feature out to me!


TinyPortal © 2005-2018