Recent

Author Topic: Can't define override method  (Read 914 times)

syntonica

  • Full Member
  • ***
  • Posts: 120
Can't define override method
« on: January 08, 2020, 06:34:27 am »
I'm trying to use the latest version of the compiler (3.1.1 Rev 43888) and either I'm not up-to-date, or it has a big bug. This compiles fine with v3.0.4.

Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$modeswitch objectivec2}
  3. unit test6;
  4.  
  5. interface
  6.  
  7. uses CocoaAll;
  8.  
  9. type
  10.  
  11. TSView = objcclass(NSView)
  12.   function isFlipped: Boolean; override;
  13. end;
  14.  
  15. implementation
  16.  
  17. function TSView.isFlipped: Boolean;
  18.   begin
  19.     Result := True;
  20.   end;
  21.  
  22. end.
  23.  
Compiling gives:
Code: Text  [Select][+][-]
  1. test6.pas(12,12) Error: There is no method in an ancestor class to be overridden: "isFlipped:Boolean;"
  2.  
If I remove the "override" decoration, I get:
Code: Text  [Select][+][-]
  1. test6.pas(12,12) Error: Inherited methods can only be overridden in Objective-C and Java, add "override" (inherited method defined in NSView)
  2.  
I'm only getting this on properties, not methods.  Am I supposed to be treating this as a Pascal property? If so, could some kind soul give me the snippet to make it work?

Thanks!

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8731
  • FPC developer.
Re: Can't define override method
« Reply #1 on: January 08, 2020, 08:17:21 am »
Afaik objective Pascal classes work different using a (hash based?) dispatch mechanism rather than VMTs.  I'm not really into Macs anymore, but my guess is that override isn't necessary or different from normal Object Pascal.

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Can't define override method
« Reply #2 on: January 08, 2020, 08:53:27 pm »
Either way, I just need it to work. In the 3.0.4, override decorators were necessary, but the messages were not since the parent had them already.  I'll file a bug report, but I wanted to be sure there wasn't a change in notation.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8731
  • FPC developer.
Re: Can't define override method
« Reply #3 on: January 08, 2020, 09:02:09 pm »
Either way, I just need it to work. In the 3.0.4, override decorators were necessary, but the messages were not since the parent had them already.  I'll file a bug report, but I wanted to be sure there wasn't a change in notation.

If your 3.0.4 experiences are also with objcclass, then what I said doesn't apply.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Can't define override method
« Reply #4 on: January 08, 2020, 10:04:29 pm »
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$modeswitch objectivec2}
  3. unit test6;
  4.  
  5. interface
  6.  
  7. uses CocoaAll;
  8.  
  9. type
  10.  
  11. TSView = objcclass(NSView)
  12.   function flipped: Boolean; override;
  13. end;
  14.  
  15. implementation
  16.  
  17. function TSView.flipped: Boolean;
  18.   begin
  19.     Result := True;
  20.   end;
  21.  
  22. end.
  23.  
you might want to use Objective-C names as a reference, rather than Swift.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Can't define override method
« Reply #5 on: January 08, 2020, 10:31:37 pm »
In this instance, the ObjC and Swift are the same:
Code: C  [Select][+][-]
  1. @property(getter=isFlipped, readonly) BOOL flipped;
  2.  
I'll go ahead and file a bug report.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Can't define override method
« Reply #6 on: January 08, 2020, 10:34:42 pm »
Yes.
After you filed the bug report, please try this code snippet:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$modeswitch objectivec2}
  3. unit test6;
  4.  
  5. interface
  6.  
  7. uses CocoaAll;
  8.  
  9. type
  10.  
  11. TSView = objcclass(NSView)
  12.   function IsFlipped: ObjCBOOL; override;
  13. end;
  14.  
  15. implementation
  16.  
  17. function TSView.IsFlipped: ObjCBOOL;
  18.   begin
  19.     Result := True;
  20.   end;
  21.  
  22. end.
  23.  
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Can't define override method
« Reply #7 on: January 08, 2020, 10:54:15 pm »
That did the trick!

Thanks.  I didn't see anything in the docs about using ObjCBOOL for Boolean.

Now I have a spurious bug report. :(

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Can't define override method
« Reply #8 on: January 08, 2020, 11:01:12 pm »
It's not spurious as long as you close it :)
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Can't define override method
« Reply #9 on: January 08, 2020, 11:14:40 pm »
I tried to but Jonas dove on it and closed it before I could... :'(

Now I can never file another bug report. Ever...  :-[

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Can't define override method
« Reply #10 on: January 09, 2020, 12:54:12 am »
he only resolved it. you need to CLOSE it
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Can't define override method
« Reply #11 on: January 09, 2020, 01:16:01 am »
he only resolved it. you need to CLOSE it
Okay. Done.


(I've never reported a bug through a bug tracker before. Can you tell?  :D [size=78%])[/size]

 

TinyPortal © 2005-2018