Please, never ever do this:

Please, never ever do this:
function TSomething.GetRecord(Buffer: {$IFDEF DELPHI_2009} RecordBuffer{$ELSE}PChar{$ENDIF}; GetMode: TGetMode; DoCheck: Boolean): TGetResult;
http://blog.dummzeuch.de/2013/07/23/using-and-ab-using-ifdef/

Comments

  1. Typical case of WET (write everything twice) in contrast to DRY (don't repeat yourself) :)

    ReplyDelete
  2. In the business world that's called artificial job security. ;-)

    I had to deal with multiple compilers recently when I attempted to write a memory manager that could be used with all versions of Delphi and free Pascal. Lost interest before I finished it but I learned an awful lot about the differences between free pascal's and Delphi's definitions of TMemoryManager(Ex). Along the way Delphi changed the type of the parameter used to hold the number of bytes to allocate when they added 64-bit support.

    I started out using ifdefs around the function signatures but it quickly became a burden to read. So instead I introduced a new type alias that was defined using ifdefs. Cleared up a lot of problems with misreading the function signatures.

    I did something similar with the definition of my implementations of TMemoryManager (free pascal's has a few more functions than Delphi's).

    ReplyDelete

Post a Comment