Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Generate Object Pascal Headers Of IOS And OSX Frameworks For Firemonkey In #Delphi 10 Berlin

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi 10 Berlin Translate Objective C to Object Pascal Header Framework IOS OSX | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDelphi 10 Berlin includes a new tool called SdkTransform which generates Object Pascal header files for IOS and OSX frameworks. The tool is command line based. HOSOKAWA Jun, a Delphi developer out of Japan, has created a Windows GUI front end in Firemonkey for SdkTransform which makes it as simple as selecting where you want to output the Objective-C Bridge files and then clicking one button to generate them all. The source code for the SDK Transform Assistant app is available on Github. I downloaded the source and compiled it under Delphi 10 Berlin. If you installed Delphi Berlin from ISO it should automatically detect the location of CLang. If you installed using the new GetIt installer you will have to set the CLang path manually. On my machine Windows 8.1 the CLang path ended up being “C:\Users\Public\Documents\Embarcadero\Studio\18.0\CatalogRepository\AndroidNDK-9c_x86_GIB.Build.22858.6822\toolchains\llvm-3.3\prebuilt\windows\lib\clang\3.3\include”. Once the paths are setup correctly and you set an output path just click start and it will generate all of the Object Pascal files. One thing to note is that you have to add the IOS and OSX frameworks that you want generated to the Delphi SDK Manager prior to generating the bridge files. Otherwise you will just get the default frameworks. Here is an excerpt created for the IOS Security framework:

const
libSecurity = ‘/System/Library/Frameworks/Security.framework/Security’;
function CF_ENUM(param1: SSLCipherSuite): Integer; cdecl;
external libSecurity name _PU + ‘CF_ENUM’;
function SecAccessControlGetTypeID: CFTypeID; cdecl;
external libSecurity name _PU + ‘SecAccessControlGetTypeID’;
function SecAccessControlCreateWithFlags(allocator: CFAllocatorRef;
protection: CFTypeRef; flags: SecAccessControlCreateFlags; error: Pointer)
: SecAccessControlRef; cdecl;
external libSecurity name _PU + ‘SecAccessControlCreateWithFlags’;

There is also an SDKTransformTypes.txt file in the Delphi Berlin bin directory which shows how SDKTransform will map the types from Objective-C to Object Pascal. Here is the complete types map list:

char=Byte
char*=MarshaledAString
short=SmallInt
short*=PSmallInt
int=Integer
int*=PInteger
long=LongInt
long*=PLongInt
float=Single
float*=PSingle
double=Double
double*=PDouble
long long=Int64
long long*=PInt64

unsigned.OSX=Cardinal
unsigned*.OSX=PCardinal
unsigned.IOS=LongWord
unsigned*.OSX=PLongWord
unsigned char=Byte
unsigned char*=PByte
unsigned char**=PByte
unsigned short=Word
unsigned int=Cardinal
unsigned int*=PCardinal
unsigned long=LongWord
unsigned long*=PLongWord
unsigned long long=UInt64
unsigned long long*=PUInt64
size_t=LongWord
size_t*=PLongWord

BOOL=Boolean
BOOL*=PBoolean
bool=Boolean

uint8_t=Byte
uint8_t*=PByte
uint8_t**=PByte
uint16_t=Word
uint16_t*=PWord
uint32_t=LongWord
uint32_t*=PLongWord
uint64_t=UInt64

__uint32_t.OSX=Cardinal
__uint32_t.IOS=LongWord

int8_t=Int8
int16_t=Int16
int32_t=Int32
int32_t*=PInt32
int64_t=Int64

UInt8=Byte
UInt16=UInt16
UInt32=UInt32
UInt64=UInt64
SInt8=Int8
SInt16=Int16
SInt32=Int32
SInt64=Int64

Float32=Single
Float64=Double
id=Pointer
id*=Pointer
void=Pointer
void*=Pointer
CGFloat*=PCGFloat

ptrdiff_t=Integer
Class=Pointer
Protocol=Pointer
Protocol*=Pointer
AppleEvent*=Pointer
GLint*=PGLint
NSGlyph*=PNSGlyph
NSGlyphInscription*=PNSGlyphInscription
NSOpenGLPixelFormatAttribute*=PNSOpenGLPixelFormatAttribute
NSPropertyListFormat*=PNSPropertyListFormat
NSRange*=PNSRange
NSRangePointer=PNSRange
NSStringEncoding*=PNSStringEncoding
NSTIFFCompression*=PNSTIFFCompression
NSTIFFCompression**=PNSTIFFCompression
NSZone*=Pointer

_Bool=Integer
_Bool*=PInteger
boolean_t=Integer
boolean_t*=PInteger
off_t=Integer
va_list=array of const
instancetype=Pointer {instancetype}
acl_t=Pointer {acl_t}
uid_t=Pointer {uid_t}
gid_t=Pointer {gid_t}
pid_t=Pointer {pid_t}
mode_t=Pointer {mode_t}
dispatch_source_t=Pointer {dispatch_source_t}
dispatch_block_t=Pointer {dispatch_block_t}
float_t=Single {float_t}
ssize_t=Integer
socklen_t=LongWord
Fixed=Integer
Fract=Integer
UnsignedFixed=LongWord
ShortFixed=SmallInt

HOSOKAWA Jun has a more extensive blog post (in Japanese) about SDKTransform, the CLang directory structure, and SDK Transform Assistant in a blog post. You can use the translate function in Chrome if needed. If you need to translate Java headers for Android try Java2OP.

Head over and read the full blog post about SDKTransform and then download the source code for the SDKTransform Assistant.

Exit mobile version