3

I would like to add some class operators to a record, but I still want to code to compile under older Delphi versions.

What define should I use so that the operator will compile in all versions that support it, but will be ignored in older Delphi versions.

type
  Iso8601 = {$ifndef UNICODE}object{$else}record{$endif}
    data: Integer;
    {$ifdef ????} <-- what to put here
    class operator Add(A: Iso8601): Iso8601;
    {$endif}
  end;

I know that records with member functions coincide with the Unicode update, but what define do I use for the class operators?

Johan
  • 74,508
  • 24
  • 191
  • 319
  • 2
    They were [`introduced in Delphi 2006`](http://delphi.about.com/od/adptips2006/qt/newdelphirecord.htm), so `{$IF CompilerVersion >= 18}`. – TLama Jun 12 '14 at 13:49
  • 1
    @TLama, you should make that an answer. – R-D Jun 12 '14 at 13:52
  • http://stackoverflow.com/questions/8460037/list-of-delphi-language-features-and-version-in-which-they-were-introduced-depre/8460108#8460108 – David Heffernan Jun 12 '14 at 14:36
  • 1
    Apparently using the compiler version was not useful as an answer... – Sertac Akyuz Jul 09 '14 at 23:23
  • 2
    It would have been nice if Embarcadero introduced a define every time they introduce a new language feature. Then we can just do: `{$ifdef class_operators} ....` – Johan Jul 12 '14 at 11:11

1 Answers1

2

As TLama said: They were introduced in Delphi 2006, so {$IF CompilerVersion >= 18}.

Also, see http://docwiki.embarcadero.com/RADStudio/XE6/en/Compiler_Versions

and see ulrichb's answer at Complete list of defines for Delphi versions about the file in Jedi.inc. It's what I use to work with different code for different compiler versions

Edit: I also like https://github.com/project-jedi/jedi/blob/master/jedi.inc because it has separate defines per language feature, e.g. SUPPORTS_CLASS_OPERATORS that you requested.

Also the "UP" defines, so e.g. DELPHIXE2_UP will be true also in XE3, XE4, 5, 6 etc

Community
  • 1
  • 1
Reversed Engineer
  • 1,095
  • 13
  • 26
  • 1
    Thanks for the answer, but please do not link to comments. They can be deleted and then your answer does not make any sense. I've updated your answer to include all the relevant info. – Johan Jul 12 '14 at 11:13