[fpc-pascal] cocoa programming without objective-pascal mode
Sven Barth
pascaldragon at googlemail.com
Mon Nov 3 07:45:50 CET 2014
On 03.11.2014 04:10, Bee wrote:
> On Mon, Nov 3, 2014 at 1:52 AM, Sven Barth <pascaldragon at googlemail.com
> <mailto:pascaldragon at googlemail.com>> wrote:
>
> How will you be cross platform if you access Cocoa directly?
>
> Take a look at Delphi. From a single source code base, we can compile it
> for Windows and Mac. Hardly any changes are required. But if you want to
> target Mac using FPC, I believe you have to use objective-pascal to
> access Cocoa API which is not compatible with Windows API. That's where
> the cross platform breaks. Am I right? CMIIW.
>
> Another example, take a look at Oxygene --another pascal language
> variant by RemObjects-- is able to target OSX, iOS, .Net, Mono, and
> Android natively without ruining their pascal syntax. Why can't FPC be
> like that? I don't understand because I'm not a compiler guy. :)
>
> Any explanation would be very much appreciated. Thank you.
That's because FireMonkey abstracts all those APIs for you. The LCL by
Lazarus has the same target: no matter whether you are on Win32/64, GTK,
Qt, Carbon, Cocoa, whatever you get the same set of APIs (the API
provided by the LCL) and you don't (normally; bugs not withstanding)
need to care about platform differences.
Even if you'd directly access Cocoa using Object Pascal means you would
not be compatible with Object Pascal codes on other platforms. The same
is true for Delphi by the way. They interface with Cocoa code using COM
interfaces which are not used on the Windows platform (for this
purpose). Two different API sets!
Also using Objective Pascal does in no way mean that you can not use
Object Pascal. You can mix them as you want and you can use Objective
Pascal classes in Object Pascal code and vice versa (otherwise this
feature would be rather useless).
So please use Objective Pascal. It will save you from quite some trouble
to implement the APIs manually (afterall there is a reason why we
implemented Objective Pascal).
Regards,
Sven
More information about the fpc-pascal
mailing list