fpc/tests/test/tobjcl2.pp
Jonas Maebe 6f3bace0f3 + support for exporting Objective-C classes from dynamic libraries. It works
the same as for exporting functions/procedures and variables: add the name
    of the class to the "exports" section of the library. By default, classes
    are only visible inside a shared library.

git-svn-id: branches/objc@13765 -
2009-09-27 15:40:52 +00:00

53 lines
971 B
ObjectPascal

{ %target=darwin }
{ %cpu=powerpc,powerpc64,i386,x86_64,arm }
{ %NEEDLIBRARY }
{$mode objfpc}
{$modeswitch objectivec1}
const
{$ifdef windows}
libname='tobjcl1.dll';
{$else}
libname='tobjcl1';
{$linklib tobjcl1}
{$endif}
type
MyLibObjCClass = objcclass(NSObject)
public
fa: byte;
function publicfun: byte; message 'publicfun';
protected
fb: byte;
function protectedfun: byte; message 'protectedfun';
private
fc: byte;
function privatefun: byte; message 'privatefun';
end; external;
MyDerivedClass = objcclass(MyLibObjCClass)
l: longint;
function callprotectedfun: byte; message 'callprotectedfun';
end;
function MyDerivedClass.callprotectedfun: byte;
begin
result:=protectedfun;
end;
var
a: MyLibObjCClass;
begin
a:=NSObject(MyDerivedClass.alloc).init;
a.fa:=55;
a.fb:=66;
if a.publicfun<>55 then
halt(1);
if MyDerivedClass(a).callprotectedfun<>66 then
halt(2);
a.release;
end.