Recent

Author Topic: Adapting code for FPC 3.2.0. Boolean or objcbool?  (Read 2121 times)

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Adapting code for FPC 3.2.0. Boolean or objcbool?
« 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';
« Last Edit: July 14, 2020, 06:17:37 pm by Igor Kokarev »

Thaddy

  • Hero Member
  • *****
  • Posts: 14199
  • Probably until I exterminate Putin.
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #1 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.
Specialize a type, not a var.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #2 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
« Last Edit: July 14, 2020, 07:07:47 pm by Igor Kokarev »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #4 on: July 14, 2020, 09:44:25 pm »
Thanks, Jonas!

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #5 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?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #6 on: July 15, 2020, 08:19:39 pm »
It's probably an NSView.inc from FPC 3.0.4.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #7 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.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Adapting code for FPC 3.2.0. Boolean or objcbool?
« Reply #9 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.
« Last Edit: July 15, 2020, 11:24:44 pm by Igor Kokarev »

 

TinyPortal © 2005-2018