Sunday, 4 March 2018

AutoSuffix

I guess everyone who had to maintain one package for several different versions of Delphi had wished this was possible to do with a single package source. The alternative is to have different set of .dpk and .dproj files, each with a different name or suffix, for each version you want to cover.

Some, including me, devised a "clever" include file that set a different {$LIBSUFFIX } for each version. So did I, but every simple change to the package would remove the {$INCLUDE 'LibSuffixes.inc'} I put in the .dpk file and replace it with something like {$LIBSUFFIX '230'} if 230 was the suffix found in the .dproj file.

If you are very careful not to modifiy the package, and the include file is not removed, this compiles as intended, i.e. a file MyPackage.dpk compiles as MyPackage250.bpl, but if you try to install that way the IDE is not aware of the changed suffix, so it complains that it could not install MyPackage.bpl.

Note: The {$LIBSUFFIX} directive works for DLLs too, but there is no entry in the Project → Options... → Description page (there is not even a Description page). The previously mentioned "clever" includes work very well for DLLs (and so for DLL-based experts too). The IDE does not meddle with the contents of a .dpr file for a library.

This problem has been discussed many times on forums and in communities. On Stack Overflow, someone called LaKraven set out to create an IDE expert (AutoSuffix) to solve this problem. But I can't find this expert anymore. All the links I found to it are dead.

The New AutoSuffix Expert

So I wrote a simple expert myself and called it AutoSuffix too.

If the current project is a package, it adds a menu item to the context menu of the Project Manager with the title Add Version Suffix, under the Rename menu item. If you click it, it sets the suffix for the package to a number that matches the suffixes used for the version of the compiler, i.e. for Delphi 10.2 Tokyo, it sets it to 250, for 10.1 Berlin to 240, for XE3 to 170, etc.

I could have made this an expert that sets the suffix automatically, but I wanted to leave the user (myself too) a choice, so it must be done manually, using the context menu.

Tested

I only tested this in Delphi XE3, Delphi 10 Seattle, 10.1 Berlin and 10.2 Tokyo, but it probably works in versions inbetween as well. I will update this as soon as I have tested it more.

Installation

Get all the files from GitHub (either clone the repository or download the files as zip) and put them in a single directory. Open the package AutoSuffix.dproj in your IDE, select the project in the Project Manager and click the Install menu item from the context menu. If all is well, this installs the expert and adds one menu item to the context menu of the Project Manager: Add Version Suffix, under the Rename item. This menu item only appears if the project is a package.

Rudy Velthuis

6 comments:

  1. LaKraven is Simon Stuart ( https://plus.google.com/+SimonStuart ). He had a bike accident some years ago and I haven't heard from him since then. I'm afraid he is still suffering from it or maybe even dead by now.

    ReplyDelete
    Replies
    1. I had seen the name Simon J. Stuart a few times, but couldn't find anything about him. Now I know why. Thanks for the info.

      Delete
  2. btw: GExperts adds a button on the Description page of a package to set the LIB suffix based on the Delphi version.
    https://blog.dummzeuch.de/2017/02/04/new-ide-enhancement-for-the-application-settings/

    ReplyDelete
    Replies
    1. Such a button is nice, but a context menu entry should be more convenient, IMO. But I didn't know this. Thanks for the heads-up.

      Delete
  3. For what it's worth: The sources do not compile with Delphi 2007 because the required OTAPI interfaces for the project manager are missing. Don't know when they were introduced, probably around XE.

    ReplyDelete
    Replies
    1. Thanks for the info. I didn't expect them to work below XE anyway. I tested them with XE3 and Seattle to Tokyo, right now. I'll do some more tests, but I don't have all versions installed. I assume that if it "works" in XE3 and Tokyo, that it works for the versions inbetween as well.

      Delete