[英]Why doesn't my algorithm for inverting character values work when they're stored in a Delphi XE2 ShortString?
I have the following code : 我有以下代码:
user_s.username := EnDecrypt(Edit_username.Text);
The function is the following : 功能如下:
function EnDeCrypt(const Value : String) : String;
var
CharIndex : integer;
begin
Result := Value;
for CharIndex := 1 to Length(Value) do
Result[CharIndex] := chr(not(ord(Value[CharIndex])));
end;
the type of variable is : 变量的类型是:
TUser = record
access: char;
username: string[25];
password: string[25];
end;
In Delphi 2007 it works, in Delphi XE2 it fails. 在Delphi 2007中它可以工作,在Delphi XE2中它可以失败。 The curious thing is that it encrypts/decrypts well the password if it is 123456789. The issue must be related with unicode and the use of shortstring.
奇怪的是,如果密码为123456789,它将很好地加密/解密。问题必须与unicode和shortstring的使用有关。 I hope there is some way to make it work in Delphi XE2 as well..
我希望也可以通过某种方式使其在Delphi XE2中工作。
用AnsiString
替换String
类型,用AnsiChar
替换Char
,该代码将与Delphi 2007中完全一样。(不过, String[25]
不应更改。)当然,您将不会获得Unicode支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.