Delphi coding hints and tips.
Which Delphi version am I ?
Within each version of Delphi, Kylix and CBuilder is a predefined conditional symbol which indicate what version compiler it uses and what platform it is running on. These are as follows:
VER40 = Turbo Pascal v4.0 VER50 = Turbo Pascal v5.0 VER55 = Turbo Pascal v5.5 VER60 = Turbo Pascal v6.0 VER70 = Turbo Pascal v7.0 VER80 = Delphi v1 VER90 = Delphi v2 VER93 = CBuilder v1 VER100 = Delphi v3 VER110 = CBuiler v3 VER120 = Delphi v4 VER125 = CBuilder v4 VER130 = Delphi v5 or CBuilder v5 VER140 = Delphi v6 or Kylix v1 & v2 MSWINDOWS = Indicates that the operating environment is Windows. WINDOWS = Indicates the the operating environment is Win16. WIN32 = Indicates that the operating environment is the Win32. LINUX = Indicates that the operating environment is Linux.
Knowing this it is possible to create code which works with different version of Delphi and Kylix using compiler directives to compile appropriate source code for each version.
As an example here's a function to add two TLargeInteger (see Windows.pas) which is a 64 bit integer used in some Win API function. In Delphi v3 this is defined as Comp type where as in Delphi v4 and v5 it's a Int64. Because of this in Delphi v3 you have to reference the Comp explicitly using QuadType. Checking for VER100 we can conditional compile the necessary code for Delphi v3.
function AddLargeIntegers(const A,B:TLargeInteger):TLargeInteger;
begin
{$IFDEF VER100}
Result.QuadPart:=A.QuadPart+B.QuadPart;
{$ELSE}
Result:=A+B;
{$ENDIF}
end;


