lazarus-ccr/bindings/objc/objcrtlutils.pas
skalogryz 1ca6ded0d7 add objcrtlutils unit
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@757 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2009-04-02 11:41:19 +00:00

66 lines
1.5 KiB
ObjectPascal

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.