Delphi 5至2010 [英] Delphi 5 to 2010
本文介绍了Delphi 5至2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Delphi 5和2010中使用了相同的函数( OneWayEncrypt(edit1.Text))。
为什么结果不同? (或者如何从Delphi 2010中获得相同的结果?)
I used same function ( OneWayEncrypt(edit1.Text) ) in Delphi 5 and 2010.
Why the results are different? (Or how can I give the same results from Delphi 2010?)
uses Sysutils, Windows, Dialogs, classes;
function OneWayEncrypt(AStr: string): string;
PROCEDURE CalcCRC32 (p: pointer; ByteCount: DWORD; VAR CRCvalue: DWORD);
implementation
const
table: ARRAY[0..255] OF DWORD =
(
//table consts are here
);
PROCEDURE CalcCRC32(p: pointer; ByteCount: DWORD; VAR CRCvalue: DWORD);
VAR
i: DWORD;
q: ^Byte;
BEGIN
q := p;
FOR i := 0 TO ByteCount - 1 DO
BEGIN
CRCvalue := (CRCvalue SHR 8) XOR table[q^ XOR (CRCvalue AND $000000FF)];
INC(q);
END
END;
function OneWayEncrypt(AStr: string): string;
var
dwCrc: DWORD;
s: string;
begin
dwCrc := $FFFFFFFF;
s := 'X' + AStr + '7F';
CalcCRC32(Addr(s[1]), Length(s), dwCrc);
result := IntToHex(dwCrc, 8);
end;
推荐答案
您知道 string
在D2010中引用Unicode字符串,而在版本<中引用AnsiString。 D2009?
Are you aware that string
refers to a Unicode string in D2010, while it refers to AnsiString in versions < D2009? That should be the source of your problem.
因此,您有两种选择:
- 您可以将所有
string
外观替换为AnsiString
。当然,在没有Unicode支持的情况下,这应能获得与D5相同的结果 - 您可以重构代码。我想这里的黑客指针至关重要。但是我不得不承认,我没有花时间完全理解代码;-)
(由于255 consts = ISO8859,很可能您的代码无论如何都不能与Unicode一起使用。 ?)
- You could replace all appearances of
string
withAnsiString
. This should give you the same results as in D5, of course without Unicode support - You could refactor your code. I guess that the pointer-"hacking" is the crucial part here. But I have to admit, I didn't take the time to fully understand the code ;-) (It could very well be that your code can't be used with Unicode anyways, due to the 255 consts = ISO8859?)
这篇关于Delphi 5至2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文