From 1ca6ded0d724af29c9d6cbf57c68e70bdbbb5443 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Thu, 2 Apr 2009 11:41:19 +0000 Subject: [PATCH] add objcrtlutils unit git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@757 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- bindings/objc/objcrtlutils.pas | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bindings/objc/objcrtlutils.pas diff --git a/bindings/objc/objcrtlutils.pas b/bindings/objc/objcrtlutils.pas new file mode 100644 index 000000000..bcec0b112 --- /dev/null +++ b/bindings/objc/objcrtlutils.pas @@ -0,0 +1,65 @@ +unit objcrtlutils; + +{$mode objfpc}{$H+} + +interface + +uses + objcrtl; + +function alloc(classname: PChar): id; inline; +function allocex(classname: PChar; extraBytes: Integer): id; inline; +function objcclass(classname: PChar): _class; inline; +function selector(cmdname: PChar): SEL; inline; +procedure release(objc: id); inline; +function AllocAndInit(classname: PChar): id; inline; +function AllocAndInitEx(classname: PChar; extraBytes: Integer): id; inline; +function super(obj: id): objc_super; + +implementation + +function super(obj: id): objc_super; +begin + Result.reciever := obj; + Result.class_ := class_getSuperclass(object_getClass(obj)); +end; + +function allocex(classname: PChar; extraBytes: Integer): id; inline; +begin + Result := class_createInstance( objcclass(classname), extraBytes); +end; + +function alloc(classname: PChar): id; inline; +begin + Result := allocex(classname, 0); + // Result := objc_msgSend( objc_getClass(classname), selector('alloc'), []); +end; + +function objcclass(classname: PChar): _class; inline; +begin + Result := _class(objc_getClass(classname)); +end; + +function selector(cmdname: PChar): SEL; inline; +begin + Result := sel_registerName(cmdname); +end; + +procedure release(objc: id); inline; +begin + objc_msgSend(objc, selector('release'), []); +end; + +function AllocAndInit(classname: PChar): id; inline; +begin + Result:= objc_msgSend( alloc( classname ), selector('init'), []); +end; + +function AllocAndInitEx(classname: PChar; extraBytes: Integer): id; inline; +begin + Result := objc_msgSend( allocEx( classname, extraBytes ), selector('init'), []); +end; + + +end. +