tobjc36.pp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. { %target=darwin }
  2. { %cpu=powerpc,powerpc64,i386,x86_64,arm,aarch64 }
  3. { Written by Jonas Maebe in 2010, released into the public domain }
  4. {$mode objfpc}
  5. {$modeswitch objectivec1}
  6. // check whether we can override methods added to a class via a category
  7. // (mainly required because the way Apple deprecates methods is by moving
  8. // them from class definitions to NSDeprecated category definitions)
  9. type
  10. MyCategory = objccategory(NSObject)
  11. procedure extraproc(a: longint); message 'extraproc:';
  12. end;
  13. MyObject = objcclass(NSObject)
  14. // overrides extraproc added to NSObject
  15. procedure extraproc(a: longint); override;
  16. end;
  17. MyObject2 = objcclass(NSObject)
  18. // overrides extraproc added to NSObject
  19. procedure extraproc(a: longint); override;
  20. end;
  21. procedure MyCategory.extraproc(a: longint);
  22. begin
  23. if a<>1 then
  24. halt(1);
  25. end;
  26. procedure MyObject.extraproc(a: longint);
  27. begin
  28. if a<>2 then
  29. halt(2);
  30. inherited extraproc(1);
  31. end;
  32. procedure MyObject2.extraproc(a: longint);
  33. begin
  34. if a<>3 then
  35. halt(3);
  36. inherited extraproc(1);
  37. end;
  38. var
  39. a: NSObject;
  40. b: MyObject;
  41. c: MyObject2;
  42. begin
  43. a:=NSObject.alloc.init;
  44. a.extraproc(1);
  45. a.release;
  46. b:=MyObject.alloc.init;
  47. b.extraproc(2);
  48. b.release;
  49. c:=MyObject2.alloc.init;
  50. c.extraproc(3);
  51. c.release;
  52. end.