问题描述
这是我第一次安装Lockbox的库.我从sourceforge下载了3.4.3版,并安装了Delphi7.第一步是要让这个傻瓜在Delphi 7下进行编译,这真是太糟糕了.我希望这些组件一经安装便更易于使用.
This is my first time installing the libraries for Lockbox. I downloaded version 3.4.3 from sourceforge and have Delphi 7. The first step is to get this sucker to compile under Delphi 7 and it's been hell. I do hope that the components are easier to use once installed.
好的.我有一个看起来像这样的单位.
Ok. I have a unit that looks like this.
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.
顺便说一句,兼容性单元将TBytes定义为TBytes =字节打包数组;
BTW, the compatibility unit defines TBytes as TBytes = packed array of byte;
Delphi 7在TEncoding上令人窒息,因为它仅存在于D2009 +中.我用什么替换该功能?
Delphi 7 chokes on the TEncoding because it only exists in D2009+. What do I replace this function with?
推荐答案
String
是Delphi 7中的8位AnsiString
.只需将TBytes
分配给字符串的Length()
和Move()
字符串内容:
String
is an 8bit AnsiString
in Delphi 7. Simply allocate the TBytes
to the Length()
of the string and Move()
the string content into it:
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()
函数将其转换为字节:
If you want to be politically correct and match what TEncoding.GetBytes()
does, you would have to convert the String
to a WideString
and then use the Win32 API WideCharToMultiBytes()
function to convert that to bytes:
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;
这篇关于如何将LockBox 3安装到Delphi 7中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!