如何从Delphi6迁移到Delphi2010(Unicode问题)

发布于 2024-10-31 00:49:39 字数 2323 浏览 1 评论 0原文

您好,我在 Delphi 6 中使用了 Francois Piette 的 RasDial,但它在 Delphi 2010 中停止工作 如何才能像以前一样继续使用这些功能?

class function Encryption.DecriptPasswd(strPasswd: string): string;  
type  
  PWORD = ^WORD;  
var  
   Buffer : String;  
   PW : String[255];
   P : PWORD;
   I : Integer;  
   V : Integer;
begin                                                                
  PW := ' ';                                                         
  P := PWORD(@PW[0]);                                                
  I := 1;                                                            
  while I <= Length(strPasswd) do                                    
  begin                                                              
    Buffer := Copy(strPasswd, I, 5);                                 
    I := I + 5;                                                      
    V := StrToInt(Buffer) - 34567;                                   
    P^ := V;                                                         
    Inc(P);                                                          
  end;                                                               
  Result := PW;                                                      
end;                                                                 

class function Encryption.EncriptPasswd(strPasswd: string): string;  
type                                                                 
  PWORD = ^WORD;                                                     
var                                                                   
  Len : Integer;                                                       
  I : Integer;                                                         
  V : DWORD;  
  P : PChar;  
  Buffer : String[255];  
begin  
  Buffer := strPasswd;  
  Len := Length(Buffer) + 1;  
  if (Len mod 2) <> 0 then  
    Inc(Len);  

  if Len < 10 then  
    Len := 10;  

  I := Length(Buffer);  
  if I = 0 then  
    Buffer := IntToStr(GetTickCount)  
  else  
    while Length(Buffer) < 10 do  
      Buffer := Buffer + Buffer;  
  SetLength(Buffer, I);  

  Result := '';  
  P := PChar(@Buffer[0]);  
  for I := 1 to Len div 2 do  
  begin  
    V := 34567 + PWORD(P)^;  
    P := P + 2;  
    Result := Result + Format('%5.5d', [V]);  
  end;  
end; 

Hi I was using the Francois Piette's RasDial with Delphi 6, but it stopped working in Delphi 2010
How can I keep using these functions like before?

class function Encryption.DecriptPasswd(strPasswd: string): string;  
type  
  PWORD = ^WORD;  
var  
   Buffer : String;  
   PW : String[255];
   P : PWORD;
   I : Integer;  
   V : Integer;
begin                                                                
  PW := ' ';                                                         
  P := PWORD(@PW[0]);                                                
  I := 1;                                                            
  while I <= Length(strPasswd) do                                    
  begin                                                              
    Buffer := Copy(strPasswd, I, 5);                                 
    I := I + 5;                                                      
    V := StrToInt(Buffer) - 34567;                                   
    P^ := V;                                                         
    Inc(P);                                                          
  end;                                                               
  Result := PW;                                                      
end;                                                                 

class function Encryption.EncriptPasswd(strPasswd: string): string;  
type                                                                 
  PWORD = ^WORD;                                                     
var                                                                   
  Len : Integer;                                                       
  I : Integer;                                                         
  V : DWORD;  
  P : PChar;  
  Buffer : String[255];  
begin  
  Buffer := strPasswd;  
  Len := Length(Buffer) + 1;  
  if (Len mod 2) <> 0 then  
    Inc(Len);  

  if Len < 10 then  
    Len := 10;  

  I := Length(Buffer);  
  if I = 0 then  
    Buffer := IntToStr(GetTickCount)  
  else  
    while Length(Buffer) < 10 do  
      Buffer := Buffer + Buffer;  
  SetLength(Buffer, I);  

  Result := '';  
  P := PChar(@Buffer[0]);  
  for I := 1 to Len div 2 do  
  begin  
    V := 34567 + PWORD(P)^;  
    P := P + 2;  
    Result := Result + Format('%5.5d', [V]);  
  end;  
end; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶ ̄淡然 2024-11-07 00:49:39

您可以首先将所有 string 声明(除了已经存在的 string[255] 声明)更改为 AnsiString,所有 CharAnsiChar,所有 PCharPAnsiChar

然后前往此处查看有关将 Unicode 之前版本的 Delphi 移植到统一码。它们的作者是 Nick Hodges,Delphi 是 CodeGear 产品时的前产品经理。它们涵盖了更改其他现有代码所需的所有详细信息。

You can start by changing all string declarations (except the string[255] ones, which already are) to AnsiString, all Char to AnsiChar, and all PChar to PAnsiChar.

Then go here for the first in a series of three articles on porting pre-Unicode versions of Delphi to Unicode. They're really well written by Nick Hodges, former Product Manager for Delphi when it was a CodeGear product. They cover all the details you need to make the changes to your other existing code.

幸福不弃 2024-11-07 00:49:39

String[255] 是短字符串(一个字节)
但是当你添加 pchar 时,它会增长两个字节乘两个字节

尝试用 pansichar 替换 pchar

String[255] is short string (one byte)
but when you add pchar, it grows two bytes by two bytes

try replace pchar by pansichar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文