Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-04

String constants to ObjC types

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dmitry Boyarintsev

Hello,

It's somewhat common task to convert a constant string to a selector. On Thu, Apr 19, 2018 at 8:43 PM, Dmitry Boyarintsev <

Show quoted text 7 lines
wrote: respondToSelector instance method https://developer.apple.com/documentation/objectivec/ 1418956-nsobject/1418583-respondstoselector?language=objc

The documentation: http://wiki.freepascal.org/FPC_PasCocoa suggests to use compiler built-in function ObjCSelector. I presume this turns the selector into a constant, thus has no impact on the runtime.

However, how hard would it be to make the compiler itself to implicitly convert a string constant to a objc selector?
As well as a constant string to a constant objective-C string (without using NSSTR())?

ObjC itself introduced @'...' syntax. (Due to C-syntax ambiguity?) Does similar ambiguity exist for Pascal syntax?

It doesn't seem to have any problems to implicitly convert constant strings to pchars, array of chars, ansistring, widestrings, OLEStrings - which is similar to NSStrings a platform specific string.

thanks,
Dmitry

Reply by email

Jonas Maebe
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 7 lines
The documentation: http://wiki.freepascal.org/FPC_PasCocoa suggests to use compiler built-in function ObjCSelector. I presume this turns the selector into a constant, thus has no impact on the runtime. However, how hard would it be to make the compiler itself to implicitly convert a string constant to a objc selector?

This is not about being hard or not, but about strong typing. And even in Objective-C itself there is no implicit conversion.

As well as a constant string to a constant objective-C string (without using NSSTR())?

It's been on the todo list since forever:
http://wiki.freepascal.org/FPC_PasCocoa#todo:

It needs a syntax and then implementation. I don't think the implementation would be very hard, but not trivial either. It would also require some research to determine whether it's the same on all architectures and for the Objective-C 1.0 and 2.0+ runtimes.

Jonas

Reply by email