Delphi 2007 の一部のレガシー コードを Delphi XE2 で動作させるのに苦労しています。
Function EncryptionWithPassword(Str,Pwd: AnsiString; Encode: Boolean): AnsiString;
var
a,PwdChk,Direction,ShiftVal,PasswordDigit : Integer;
begin
PasswordDigit := 1;
PwdChk := 0;
for a := 1 to Length(Pwd) do Inc(PwdChk,Ord(Pwd[a]));
Result := PChar(Str);
If Encode then Direction := -1 else Direction := 1;
for a := 1 to Length(Result) do
begin
if Length(Pwd)=0 then
ShiftVal := a
else
ShiftVal := Ord(Pwd[PasswordDigit]);
if Odd(A) then
Result[A] := RotateBits(Result[A],-Direction*(ShiftVal+PwdChk))
else
Result[A] := RotateBits(Result[A],Direction*(ShiftVal+PwdChk));
inc(PasswordDigit);
if PasswordDigit > Length(Pwd) then PasswordDigit := 1;
end;
end;
Function RotateBits(C: Char; Bits: Integer): Char;
var
SI : Word;
begin
Bits := Bits mod 8;
// Are we shifting left?
if Bits < 0 then
begin
// Put the data on the right half of a Word (2 bytes)
SI := MakeWord(Byte(C),0);
// Now shift it left the appropriate number of bits
SI := SI shl Abs(Bits);
end
else
begin
// Put the data on the left half of a Word (2 bytes)
SI := MakeWord(0,Byte(C));
// Now shift it right the appropriate number of bits
SI := SI shr Abs(Bits);
end;
// Now OR the two halves together
SI := Lo(SI) or Hi(SI);
Result := Chr(SI);
end;
何を試しても、関数は文字列を破損します。AnsiString チートを適用した後、文字の配列などを使用してみましたが、何も機能しません。洞察力のある人が支援および説明できる場合は、お願いします-私は機知に富んでいて、巨大なプロジェクトを遅らせています。