Pergunta

I have a unit I wrote in Delphi 7 some time ago, and have just had the fun (pain) of converting to Delphi XE (Unicode).

The Unit works fine after some trouble, I am now trying to make this unit compatible with different Delphi Versions should I ever need to switch IDE back to Delphi 7 whilst updating some other code.

I only have Delphi 7 and Delphi XE, but from what I gather code written in Delphi 1 to Delphi 2007 will compile, but code from Delphi 2009 and above will be Unicode.

...Anyway, in the Unit I am separating the non-unicode and unicode like so:

{$IFDEF VER150} //Delphi 7
// code
{$ELSE IFDEF VER220} //Delphi XE
// code
{$ENDIF}

How do I modify the compiler directive so the rules apply to multi versions? For example something like:

{$IFDEF VER80,  //D1
        VER90,  //D2
        VER100, //D3
        VER120, //D4
        VER130, //D5
        VER140, //D6
        VER150, //D7}

This would then cover all Delphi versions should I distribute the source or .dcu unit.

Thanks.

Foi útil?

Solução

I wonder if the simplest approach in this instance is to switch behaviour on the UNICODE conditional. This conditional is defined if and only if you are using a Unicode version of Delphi, i.e. in Delphi 2009 and later. The big advantage of this is that it is future proof—you don't need to update your code every time a new Delphi is released. What's more, the conditional switch will be far more readable since it will clearly express the intent.

The Delphi documentation has an excellent topic listing all the pre-defined conditionals. The full list of version conditionals is also linked from there.

Outras dicas

Your best bet is actually to look at one of the many JEDI projects, http://sourceforge.net/projects/jedi-apilib/ for example and look at how they do it. They have common include files that contain exactly the details you are interested in. JVCL is another good choice ...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top