Search code examples
delphiconditional-compilation

Delphi $IFDEF WIN32 falls through to $ELSE


A project I'm working on has a unit, xprocs.pas that has an {$IFDEF}/{$ELSE} block that's acting up. It was building fine and ran without issue yesterday... This morning however, it's throwing an exception with a range check error. The block of code where the error is thrown is proceeded by {$IFDEF WIN32}, but isn't acting as expected.

If I comment the {$IFDEF} block and attempt to only run the line directly following it, it doesn't respect the comment, and runs it anyway. Also the IDE allows me to place a break point on the code that's commented out.

IDE Image

I've deleted the DCU file thinking it was using an old version, but with no effect.

Any suggestions?

const
  C1 = 52845;
  C2 = 22719;

function strEncrypt(const S: String; Key: Word): String;
var
  I: Integer;
begin
 {$IFDEF Win32}
  SetLength(Result,Length(S));
 {$ELSE}
   Result[0]:=Chr(Length(S));
 {$ENDIF}
  for I := 1 to Length(S) do begin
    Result[I] := Char(Ord(S[I]) xor (Key shr 8));
    Key := (Ord(Result[I]) + Key) * C1 + C2;
  end;
end;

Solution

  • The issue ended up being a corrupt project file, "ProjectName.dof". I deleted it and copied over the compiler settings and search path from the old one manually.