fpc/tests/test/tobjc36.pp
Jonas Maebe f29598384b * Objective-Pascal inferred result type and improved category method searching
--- Merging r42815 through r42817 into '.':
U    tests/test/tobjc34.pp
U    tests/test/tobjc36.pp
U    tests/test/tobjcl2.pp
A    tests/test/units/cocoaall
A    tests/test/units/cocoaall/tw35994.pp
U    compiler/defcmp.pas
U    compiler/ncal.pas
C    compiler/pdecl.pas
C    compiler/symconst.pas
C    compiler/utils/ppuutils/ppudump.pp
U    compiler/symtable.pas
--- Recording mergeinfo for merge of r42815 through r42817 into '.':
 U   .
--- Merging r42857 into '.':
G    compiler/symtable.pas
--- Recording mergeinfo for merge of r42857 into '.':
 G   .
  

git-svn-id: branches/fixes_3_2@42883 -
2019-08-31 11:43:41 +00:00

64 lines
1.3 KiB
ObjectPascal

{ %target=darwin }
{ %cpu=powerpc,powerpc64,i386,x86_64,arm,aarch64 }
{ Written by Jonas Maebe in 2010, released into the public domain }
{$mode objfpc}
{$modeswitch objectivec1}
// check whether we can override methods added to a class via a category
// (mainly required because the way Apple deprecates methods is by moving
// them from class definitions to NSDeprecated category definitions)
type
MyCategory = objccategory(NSObject)
procedure extraproc(a: longint); message 'extraproc:';
end;
MyObject = objcclass(NSObject)
// overrides extraproc added to NSObject
procedure extraproc(a: longint); override;
end;
MyObject2 = objcclass(NSObject)
// overrides extraproc added to NSObject
procedure extraproc(a: longint); override;
end;
procedure MyCategory.extraproc(a: longint);
begin
if a<>1 then
halt(1);
end;
procedure MyObject.extraproc(a: longint);
begin
if a<>2 then
halt(2);
inherited extraproc(1);
end;
procedure MyObject2.extraproc(a: longint);
begin
if a<>3 then
halt(3);
inherited extraproc(1);
end;
var
a: NSObject;
b: MyObject;
c: MyObject2;
begin
a:=NSObject.alloc.init;
a.extraproc(1);
a.release;
b:=MyObject.alloc.init;
b.extraproc(2);
b.release;
c:=MyObject2.alloc.init;
c.extraproc(3);
c.release;
end.