When i try to compile my code I get the below error. Could anyone suggest what am I doing wrong here?
W1000 Symbol 'StrPas' is deprecated: 'Moved to the AnsiStrings unit'
The code fragment that i'm trying to compile is:
{$IFDEF NEWVER} // Codegear delphi 2009 d12.0
StrCopy(pSerialNumber, @Buf[pDevDesc.SerialNumberOffset + 1]);
{$ELSE}
StrPCopy(pSerialNumber,
FlipAndCodeBytes(StrPas(@Buf[pDevDesc.SerialNumberOffset + 1])));
{$ENDIF}
Trying to decipher the previous programmer's intent leads to another possibility....
It seems there was a fix applied for Delphi 2009 due to the changes in the string type. I'm sure you don't want to reinvent all the fixes that another programmer has already done.
Looking at the code, Delphi 2009 is intended to compile the following line (which doesn't use StrPas
):
StrCopy(pSerialNumber, @Buf[pDevDesc.SerialNumberOffset + 1]);
And older versions of Delphi are intended to compile the following line (which does use StrPas
):
StrPCopy(pSerialNumber,
FlipAndCodeBytes(StrPas(@Buf[pDevDesc.SerialNumberOffset + 1])));
Delphi XE-6 would not in this case be classified as an "older version", so the error is that you're compiling the wrong branch of the conditional code.
The conditional code will compile the first statement if NEWVER
is defined. So if you ensure that NEWVER
is defined you should be compiling the correct line. You might need to modify an appropriate include file, or set the conditonal as an option in the project file. (It depends on how your environment is set up.)
However the name of that conditional symbol NEWVER
is somewhat inappropriate. Clearly 2009 is no longer the "new version" - in fact even XE6 is now an "older version".
So you may want to rewrite your conditional as follows:
{$IF CompilerVersion >= 20.0} //>= Delphi 2009
StrCopy(pSerialNumber, @Buf[pDevDesc.SerialNumberOffset + 1]);
{$ELSE}
StrPCopy(pSerialNumber,
FlipAndCodeBytes(StrPas(@Buf[pDevDesc.SerialNumberOffset + 1])));
{$IFEND}
See the following links for more information on conditional defines:
http://docwiki.embarcadero.com/RADStudio/XE7/en/Conditional_compilation_(Delphi) http://docwiki.embarcadero.com/RADStudio/XE7/en/Compiler_Versions
If you need to support much older versions of Delphi (older than Delphi 6 if I'm not mistaken), you may need to write the above code as:
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF CompilerVersion >= 20.0} //>= Delphi 2009
StrCopy(pSerialNumber, @Buf[pDevDesc.SerialNumberOffset + 1]);
{$ELSE} //< Delphi 2009
StrPCopy(pSerialNumber,
FlipAndCodeBytes(StrPas(@Buf[pDevDesc.SerialNumberOffset + 1])));
{$IFEND}
{$ELSE} //< Delphi 6
StrPCopy(pSerialNumber,
FlipAndCodeBytes(StrPas(@Buf[pDevDesc.SerialNumberOffset + 1])));
{$ENDIF}