访问冲突在Delphi 10.2 Tokyo中移植32到64位

问题描述 投票:-1回答:1

试图将一些代码从32位delphi移植到64.编译后我得到一个访问违规在64位补丁的这一行(在32上工作正常)

 PByte = ^Byte;

function TyDecoder.findCRLF(pStart,pEnd: PByte): PByte;
begin
 while (Not (((pStart^=13) and (pByte(Integer(pStart)+1)^=10)) or (pStart^=10))) and (Integer(pStart)<Integer(pEnd))   do Inc(pStart);
 Result:=pStart;
end;

以前有许多问题从D7移植到10.2东京但是通过将所有字符串声明更改为Ansistring来纠正这些问题。

我猜这可能与指针类型有关,现在是8而不是4。

难住了。

delphi 64-bit
1个回答
6
投票

您已经被告知可以使用NativeInt(或NativeUInt)来获取指针大小的整数。但是对于Delphi 10.2,你的表达仍然是不必要的。 Delphi的PByte(不是你的,所以不要自己定义)可以做指针数学,所以试试:

function TyDecoder.findCRLF(pStart, pEnd: PByte): PByte;
begin
  while (not (((pStart[0] = 13) and (pStart[1] = 10)) or (pStart[0] = 10))) and
        (pStart < pEnd) do
    Inc(pStart);    
  Result := pStart;
end;

你可以使用pStart[0]而不是pStart^而不是pStart[1],你可以使用(pStart + 1)^,如果你愿意的话。

另请阅读online documentation about pointer math in Delphi

© www.soinside.com 2019 - 2024. All rights reserved.