fpc/tests/test/tobjc36a.pp
Jonas Maebe 1633341906 * treat methods added via an objccategory to an objcclass in exactly the
same way as regular methods as far as overriding is concerned ("override"
    is now allowed, and even required, to override them in a descendent class;
    and similarly, "reintroduce" must be used if a category wants to replace
    a method in a child class if that method was  added by another category in
    a parent class)
  * print the name of owning objcclass/category of the original method in case
    override/reintroduce is missing for objc methods, since this is no longer
    always the parent class

git-svn-id: trunk@16035 -
2010-09-22 21:26:58 +00:00

47 lines
834 B
ObjectPascal

{ %target=darwin }
{ %cpu=powerpc,powerpc64,i386,x86_64,arm }
{ %fail }
{ Written by Jonas Maebe in 2010, released into the public domain }
{$mode objfpc}
{$modeswitch objectivec1}
type
MyObject2 = objcclass(NSObject)
end;
MyCategory = objccategory(MyObject2)
procedure extraproc(a: longint); message 'extraproc:';
end;
MyObject = objcclass(NSObject)
// overrides extraproc added to NSObject
procedure extraproc(a: longint); override; message 'extraproc:';
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);
end;
var
a: NSObject;
b: MyObject;
begin
a:=NSObject.alloc.init;
a.extraproc(1);
a.release;
b:=MyObject.alloc.init;
b.extraproc(2);
b.release;
end.