[fpc-devel] OSX: Setting up parameters to objc_msgSend()

Dmitry Boyarintsev skalogryz.lists at gmail.com
Fri Oct 12 17:09:59 CEST 2018


On Fri, Oct 12, 2018 at 10:38 AM David Jenkins <david at scootersoftware.com>
wrote:

> The movsbl %dl, %edx is good.  Unfortunately the value of %edx is
> 0xffffffff not 0x00000001.  This is the same result I saw when I changed it
> to LongBool.
>

I presume this is due to the definition of YES macro in objc, which is 1
(rather than ~NO)
https://developer.apple.com/documentation/objectivec/objective-c_runtime/boolean_values?language=objchttps://developer.apple.com/documentation/objectivec/bool

so, far the only reliable approach to fix the issue (for the current
compiler version) is something like that:

unit cocoa_extra;

type
  OBJCBOOL = ShortInt;
...
  NSMenuFix = objccategory external (NSMenu)
    function itemAtIndex(index: NSInteger): NSMenuItem; message
'itemAtIndex:';
    function setEnabled_(aenabled:  OBJCBOOL ): NSMenuItem; message
'setEnabled:'; // same method, different parameter type
  end;

class function TCocoaWSMenuItem.SetEnable(const AMenuItem: TMenuItem;
   const Enabled: boolean): boolean;
begin
   Result:=Assigned(AMenuItem) and (AMenuItem.Handle<>0);
   if not Result then Exit;
   NSMenuItem(AMenuItem.Handle).setEnabled_( Ord(Enabled) ); // totally
matches ObjC YES / NO definitions
end;

Not really sure, if it can be properly be solved through the compiler.
Because it either would break Boolean (_Bool) or ByteBool.
OR ByteBool needs to be more strict on it's Ord() value (optionally?)

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20181012/ef887563/attachment.html>


More information about the fpc-devel mailing list