首页 文章

如何将LockBox 3安装到Delphi 7中?

提问于
浏览
2

这是我第一次为Lockbox安装库 . 我从sourceforge下载了3.4.3版本并使用了Delphi 7.第一步是让这个sucker在Delphi 7下编译,这一直是地狱 . 我希望安装后组件更容易使用 .

好 . 我有一个看起来像这样的单位 .

unit uTPLb_StrUtils;

interface

uses
  SysUtils, uTPLb_D7Compatibility;

function AnsiBytesOf(const S: string): TBytes;

implementation

function AnsiBytesOf(const S: string): TBytes;
begin
//compiler chokes here
  **Result := TEncoding.ANSI.GetBytes(S);**
end;

end.

BTW,兼容性单元将TBytes定义为TBytes =打包的字节数组;

Delphi 7在TEncoding上窒息,因为它只存在于D2009中 . 我该用什么替换这个功能?

3 回答

  • 0

    String 是Delphi 7中的8位 AnsiString . 只需将 TBytes 分配给字符串的 Length() ,将 Move() 字符串内容分配到其中:

    function AnsiBytesOf(const S: AnsiString): TBytes;
    begin
      SetLength(Result, Length(S) * SizeOf(AnsiChar));
      Move(PChar(S)^, PByte(Result)^, Length(Result));
    end;
    

    如果你想在政治上正确并匹配 TEncoding.GetBytes() 的作用,你必须将 String 转换为 WideString ,然后使用Win32 API WideCharToMultiBytes() 函数将其转换为字节:

    function AnsiBytesOf(const S: WideString): TBytes;
    var
      Len: Integer;
    begin
      Result := nil;
      if S = '' then Exit;
      Len := WideCharToMultiByte(0, 0, PWideChar(S), Length(S), nil, 0, nil, nil);
      if Len = 0 then RaiseLastOSError;
      SetLength(Result, Len+1);
      WideCharToMultiByte(0, 0, PWideChar(S), Length(S), PAnsiChar(PByte(Result)), Len, nil, nil);
      Result[Len] = $0;
    end;
    
  • 0
    function Quux(const S: AnsiString): TBytes;
    var
      Count: Integer;
    begin
      Count := Length(S) * SizeOf(AnsiChar);
      {$IFOPT R+}
      if Count = 0 then Exit; // nothing to do
      {$ENDIF}
      SetLength(Result, Count);
      Move(S[1], Result[Low(Result)], Count);
    end;
    
  • 4

    你可以在这里获得LB 3.5:

    http://lockbox.seanbdurkin.id.au/Grok+TurboPower+LockBox

    请尝试3.5 .

相关问题