Recent

Author Topic: Porting application to MacOS  (Read 6258 times)

Frantic

  • New Member
  • *
  • Posts: 18
Porting application to MacOS
« on: August 18, 2010, 06:10:42 pm »
Hi everyone!

I just ended porting my app from Delphi to Lazarus. Now it's time to compile it under Mac! But it's not an easy task. Lazarus for Mac doesn't have "Windows" unit, it doesn't like "{$R Form1.lrs}" directives and has troubles with "for s in MyStringList" enumeration...

Is there some information on how programming in Lazarus for Mac differs from programming in Lazarus for Windows? Tips and tricks? Blogs about Mac development using Lazarus?

Thanks for any help!

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3646
  • I like bugs.
Re: Porting application to MacOS
« Reply #1 on: August 18, 2010, 08:40:38 pm »
I just ended porting my app from Delphi to Lazarus. Now it's time to compile it under Mac! But it's not an easy task. Lazarus for Mac doesn't have "Windows" unit, it doesn't like "{$R Form1.lrs}" directives and has troubles with "for s in MyStringList" enumeration...

If you have Windows specific code like API calls or OLE automation, then you must change it.
Remove Windows unit and replace the calls with something cross-platform.
If you design the program from the beginning to be cross-platform, it can be compiled with no changes on OSX.
"for s in MyStringList" enumeration is compiler version specific, not platform specific. You must either install a new FPC on Mac or change the syntax of your code.
I don't know why it doesn't accept "{$R Form1.lrs}".


Quote
Is there some information on how programming in Lazarus for Mac differs from programming in Lazarus for Windows? Tips and tricks? Blogs about Mac development using Lazarus?

General cross platform rules apply. I code on Linux myself and can compile on OSX without changes.

http://wiki.lazarus.freepascal.org/Code_Conversion_Guide
http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide

Juha

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Porting application to MacOS
« Reply #2 on: August 19, 2010, 04:20:45 am »
I just ended porting my app from Delphi to Lazarus. Now it's time to compile it under Mac! But it's not an easy task. Lazarus for Mac doesn't have "Windows" unit, it doesn't like "{$R Form1.lrs}" directives and has troubles with "for s in MyStringList" enumeration...

Is there some information on how programming in Lazarus for Mac differs from programming in Lazarus for Windows? Tips and tricks? Blogs about Mac development using Lazarus?

Delphi sticks Windows into the uses statement of each form whether you need to call a Windows API function or not. Try taking out "Windows, Messages" and substituting "LclIntf, LMessages, LType". These are cross-platform units - LclIntf has a subset of the Win API functions (although a few are not implemented on all widgetsets). Now try compiling it on Windows. If it doesn't compile, you'll need to eliminate or isolate the stuff that's still Windows-specific.

Surely you mean "{$R Form1.lfm}"? Embedding an .lrs file as a resource wouldn't make sense. Are you compiling with at least FPC 2.4.0 on OS X?

I'm not familiar with the "for s in" syntax in Pascal. That must be something that has been introduced in an experimental version of FPC, but not yet in a stable version. If you want to retain support for that syntax, you'll need to build FPC 2.5.1 from SVN on your Mac and likely Lazarus too since no snapshot .dmg includes a version of FPC later than 2.4.0.

As long as you're going to build 2.5.1, you might investigate using Cocoa directly rather than Carbon via LCL. FPC 2.5.1 has a new {$MODESWITCH ObjectiveC1} directive which, as I've written elsewhere, allows you to "use and declare Objective C classes, categories and protocols in Pascal, thereby allowing you to work directly with Cocoa classes without the need for any "bridge" or intermediate layer" - i.e, a pretty cool extension to Pascal.

It depends on what you're doing. If you're like most Laz developers, meaning a hobbyist programmer or writing code for yourself, then the Carbon framework-based widgetset will do fine. But this is probably is not suitable for production code for a client or employer, who if they know better will want a Cocoa-based app.

In the unlikely event you're interested in actual Cocoa programming for the Mac, you might take a look at these blogs that somebody put together (not sure who):

http://delphitococoa.wordpress.com/concept-comparison/

http://delphitococoa.wordpress.com/

I also wrote a series of short articles covering some of the aspects of cross-platform programming that were of interest to me last winter:

http://web.me.com/macpgmr/

Click on the Objective Pascal link.

Thanks.

-Phil

Frantic

  • New Member
  • *
  • Posts: 18
Re: Porting application to MacOS
« Reply #3 on: August 19, 2010, 05:05:17 pm »
General cross platform rules apply. I code on Linux myself and can compile on OSX without changes.
Juha, thank you for links, I don't know how I missed them :)

Quote from: Phil
Surely you mean "{$R Form1.lfm}"? Embedding an .lrs file as a resource wouldn't make sense.
Yes. I found a solution - using {$I <unit_name>.lrs} in initialization section works on Mac.

Quote from: Phil
In the unlikely event you're interested in actual Cocoa programming for the Mac
I want to know about Cocoa framework, it's basics, concepts and API.

Quote from: Phil
I also wrote a series of short articles covering some of the aspects of cross-platform programming that were of interest to me last winter
Very interesting articles! I wish you continue...

Also, how do you think, does LCL for Cocoa have future?