秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1、从delphi转lazarus for linux,如果原来代码用CopyMemory和ZeroMemory编译时会出错。移植代码时可以用move替换CopyMemory,FillChar替换ZeroMemory,最简单的方法是自己按以下方法写CopyMemory和ZeroMemory。

{$ifdef linux}
procedure CopyMemory(Destination, Source:pointer; Length:DWORD);
begin
  Move(Source^, Destination^, Length);
end;

procedure ZeroMemory(Destination:pointer; Length:DWORD);
begin
  FillChar(Destination^,Length,#0);
end;
{$endif} 

2、TEncoding.Default.GetBytes(IvStr);返回的不是正确的,用StrToBytes替换TEncoding.Default.GetBytes就可以。

function StrToBytes(const S: AnsiString): TBytes;
begin
  if S <> '' then
  begin
    SetLength(Result, Length(S));
    Move(S[1], Result[0], Length(S));
  end
  else
    Result := nil;
end;

function BytesToStr(Data: TBytes): AnsiString;
begin
  if Length(Data) > 0 then
  begin
    SetLength(Result, Length(Data));
    Move(Data[0], Result[1], Length(Data));
  end
  else
    Result := '';
end;

 

      IvBytes := TEncoding.Default.GetBytes(IvStr);
改为:
      IvBytes := StrToBytes(IvStr);

 

posted on 2023-03-29 10:39  秋·风  阅读(638)  评论(0)    收藏  举报