[Estimated Reading Time: 2 minutes]

I am in the middle of writing a much longer post about variations and recent additions to Pascal syntax in Delphi, Oxygene and Lazarus, but at the same time I also decided to start on the process of migrating some of my code to Lazarus and FPC. In the process I have hit upon a snag.

Ever since I discovered that Delphi 7 (SEVEN!) supported “dotted unit names”, I have adopted this style of unit naming in my own code organisation. In Delphi 7 this incurred some less than desirable behaviours in the IDE, since the support for dotted unit names was at that time a little… preliminary.

Sadly, this means that – as far as I can tell – none of my existing units can be used “as-is” in Lazarus and FPC. There is no support for dotted unit names there, not even with FPC set to “Delphi” syntax parsing.

At first I thought this meant that my Lazarus/FPC ambitions were stalled at a disappointingly early stage.

However, not to be deterred I quickly I found that several suggestions have already been made as to how FPC might go about implementing dotted unit names, some of which aim to improve on the approach in Delphi (though in Delphi mode I would expect things to behave in as Delphi-like a way as possible, obviously).

Then I found that some support in this area has already made it’s way into the latest development version of the FPC compiler.

All I need to do now is figure out how to get Lazarus working with this later, pre-release build of the FPC compiler (something which I gather is possible, just not “plug-and-play”). I also need to be a little cautious as, being pre-release, whatever form the dotted unit name support in the current FPC trunk takes, it could still change.

29 thoughts on “Going Dotty With Lazarus/FPC”

  1. Hm. I don’t think using dots in Unit-Names makes much sense.
    All it does is to create additional ambiguities for the parser and to the reader
    of your code whenever you prefix a type with a Unit-Name.
    Why don’t you just use CamelCase or underscores?

    1. If you only use CamelCase for long unit names one can’t quickly see which part of the unit name is only a prefix and which is relevant in my current namespace. They are used in Delphi, Java, C#, … and in my opinion this has many advantages.

      Underscores? Do you mean this serious? For external API identifiers this is ok, but for identifiers in own code? omg… in my opinion code with underscores looks really dirty.

    1. Yep, as I understand it Lazarus 1.0 supports them in the IDE (in the sense that it no longer rejects them in various places as “invalid identifiers”) but the FPC version that is in the release distro (FPC 2.6.0) does not. Dotted unit names is in FPC 2.7.x and is subject to change.

  2. There are daily snapshots of Lazarus with FPC 2.7.1 just google for it. Last time I checked (few months ago) it was pretty much broken but the dotted unit names worked.

  3. Getting Lazarus to work (on Windows at least) is as simple as:
    – Getting a copy of the fpc source somewhere using svn
    – Compiling this code (starting with the old compiler version should work)
    – Pointing to the new compiler and source in the lazarus compiler options
    – Rebuild Lazarus

    1. Yes, simple, but not plug-and-play and quite a few manual steps in the process (the instructions I found included creating a BAT file necessary to compile the compiler). At the time that I came across this I had plenty of other, more important things to do. By the time I’ve done those the feature might be stabilised and part of a more straightforward install (the stabilised part is the most important to me).

      1. I don’t recommend running Lazarus with 2.7.1 for production anyway. (and it will probably remain that way quite a while).

        This because 2.7.1 changes things in unicode support (D2009+ like) that Lazarus hasn’t adapted too.

        That being said, IMHO dotted units isn’t exactly the nicest feature. One I would gladly do without (yes I know XE2 makes it near mandatory, which is why I’m on XE)

  4. I’m not completely sure, but I guess & symbol isn’t included in FPC 2.6.0 release also.

    Like:

    var
    &Type: integer; // though it works in 2.7.1

    You can check it also.

    1. Maybe, maybe not. But this feature in Delphi is one of those that breaks the IDE (up to and including XE2 at least) so I never use it (try using Class Completion when your class includes a property that uses the ‘&’ prefix).

  5. This new release also supports the Java Virtual Machine and Dalvik targets, so the RemObjects Oxygene now has a free competitor.

  6. You have to keep in mind that FPC 2.6.0 was released at the beginning of 2012. Even more it was branched last year in July/August, so many of the more intrusive features (regarding compiler code) were not merged to that branch (some smaller ones were included in 2.6.1 and thus will be part of 2.6.2). Features that are only supported in 2.7.1 for example are – as you noticed – dotted unit names and the code page aware string.

    Just in case: if you heavily use generics in your Delphi code you should use 2.7.1 as 2.6.0 is not nearly as compatible as 2.7.1 is (though things like constraints and generic methods are still missing and inline specialization is not yet working as flawless as possible – I’m working on them 😉 ).

    Regards,
    Sven

  7. Have a look at codeTyphon. Has Lazarus+FreePascal+Tools+Free Components packages+Free Libraries and is normaly build from the latest fpc / lazarus trunk.

    Hope it helps

    cu Ha-Joe

      1. I’ll correct myself, it seems CodeTyphoon rebuilds the latest CSV, just tried it and got Lazarus 1.1

        This is getting better and better 🙂

Comments are closed.