tobjcl2.pp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. { %target=darwin }
  2. { %cpu=powerpc,powerpc64,i386,x86_64,arm,aarch64 }
  3. { %NEEDLIBRARY }
  4. { Written by Jonas Maebe in 2009, released into the public domain }
  5. {$mode objfpc}
  6. {$modeswitch objectivec1}
  7. const
  8. {$ifdef windows}
  9. libname='tobjcl1.dll';
  10. {$else}
  11. libname='tobjcl1';
  12. {$linklib tobjcl1}
  13. {$endif}
  14. type
  15. MyLibObjCClass = objcclass external (NSObject)
  16. public
  17. fa: byte;
  18. function publicfun: byte; message 'publicfun';
  19. protected
  20. fb: byte;
  21. function protectedfun: byte; message 'protectedfun';
  22. private
  23. fc: byte;
  24. function privatefun: byte; message 'privatefun';
  25. end;
  26. MyDerivedClass = objcclass(MyLibObjCClass)
  27. l: longint;
  28. function callprotectedfun: byte; message 'callprotectedfun';
  29. end;
  30. function MyDerivedClass.callprotectedfun: byte;
  31. begin
  32. result:=protectedfun;
  33. end;
  34. var
  35. a: MyLibObjCClass;
  36. begin
  37. a:=MyDerivedClass.alloc.init;
  38. a.fa:=55;
  39. a.fb:=66;
  40. if a.publicfun<>55 then
  41. halt(1);
  42. if MyDerivedClass(a).callprotectedfun<>66 then
  43. halt(2);
  44. a.release;
  45. end.