Lazarus

Programming => Widgetset => Cocoa => Topic started by: Igor Kokarev on July 14, 2020, 06:12:20 pm

Title: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 14, 2020, 06:12:20 pm
This code doesn't compile in FPC 3.2.0 on macOS:

Code: Pascal  [Select][+][-]
  1. TMyWindow = objcclass (NSWindow)
  2. public
  3.   function canBecomeKeyWindow: Boolean; message 'canBecomeKeyWindow'; override;
  4. end;
  5.  
  6. ...
  7.  
  8. function TMyWindow.canBecomeKeyWindow: Boolean;
  9. begin
  10.   Result:=True;
  11. end;

I get:
Quote
"Error: There is no method in an ancestor class to be overridden: "canBecomeKeyWindow:Boolean;"

I tried to replace Boolean to objcbool and now this code works fine. Does it correct change?

Code: Pascal  [Select][+][-]
  1.   TMyWindow = objcclass (NSWindow)
  2.   public
  3.     function canBecomeKeyWindow: objcbool; message 'canBecomeKeyWindow'; override;
  4.   end;

I don't understand why I had to add this change, because NSWindow.inc has the following declaration for NSWindow:

Code: Pascal  [Select][+][-]
  1. function canBecomeKeyWindow: Boolean; message 'canBecomeKeyWindow';
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Thaddy on July 14, 2020, 06:17:00 pm
I can not test this anymore (Mac Mini died) but are you sure the original is declared virtual? Because otherwise that leads to the issue you describe:
The root declaration needs to be virtual for override to be possible.
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 14, 2020, 06:43:34 pm
Yes, all methods of NSWindow declared in NSWindow.inc are NOT virtual.

But I need to override canBecomeKeyWindow() to receive keyboard events in a borderless NSWindow. I create custom NSWindows without LCL.

P.S. I hope that you can repair your Mac.

UPD. I used the solution described here:
https://stackoverflow.com/questions/30776875/how-to-set-canbecomekeywindow
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Jonas Maebe on July 14, 2020, 07:23:37 pm
https://wiki.freepascal.org/User_Changes_3.2.0#objcbase

And all Objective-C methods are always virtual: https://wiki.freepascal.org/FPC_PasCocoa#Method_declaration
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 14, 2020, 09:44:25 pm
Thanks, Jonas!
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 15, 2020, 08:35:54 am
I only wonder, why NSWindow.inc contains Boolean as a result in all methods and I have to use ObjCBool for overriding?
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Jonas Maebe on July 15, 2020, 08:19:39 pm
It's probably an NSView.inc from FPC 3.0.4.
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 15, 2020, 09:09:24 pm
No, these units from fpc 3.2.0. Not only NSWindow.inc, at least one more unit, too.
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Jonas Maebe on July 15, 2020, 09:15:08 pm
This is the NSView.inc from FPC 3.2.0: https://svn.freepascal.org/svn/fpc/tags/release_3_2_0/packages/cocoaint/src/appkit/NSView.inc
Title: Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
Post by: Igor Kokarev on July 15, 2020, 11:10:10 pm
Jonas,

You're right. I checked SVN for FPC 3.2.0. Yes, they use ObjCBool for NSWindow and for other units.

I checked my files. It seems that FPC 3.2.0 Sources was installed wrongly for this folder suggested by default:

/usr/local/share/fpcsrc/3.2.0

keeping old FPC 3.0.4 sources in:

/usr/local/share/fpcsrc/

So Lazarus reads old FPC sources from /usr/local/share/fpcsrc
It occured on both my Macs after upgrading Lazarus 2.0.6 + fpc 3.0.4 to 2.0.10 + fpc 3.2.0

Solution: I removed /fpcsrc folder and re-installed FPC 3.2.0 sources.
TinyPortal © 2005-2018