D2007 中的指针算术如何使其工作?

发布于 2024-12-20 22:13:50 字数 1099 浏览 2 评论 0原文

在 Delphi 2007 中编译 Embarcadero VirtualShellTools 时: http://embtvstools.svn.sourceforge.net/

function TShellIDList.InternalChildPIDL(Index: integer): PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
begin
  if Assigned(FCIDA) and (Index > -1) and (Index < PIDLCount) then
    Result := PItemIDList( PByte(FCIDA) 
                         + PDWORD(PByte(@FCIDA^.aoffset)
                                  +sizeof(FCIDA^.aoffset[0])*(1+Index))^)
  else
    Result := nil
end;

我得到这个错误:

[Pascal 错误] IDVirtualDataObject.pas(1023): E2015 运算符不适用于此操作数类型

此代码有什么问题以及我需要进行哪种类型转换才能使其真正工作?

我在以下(不太复杂的)例程中遇到相同的错误:

function TShellIDList.InternalParentPIDL: PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
begin
  if Assigned(FCIDA) then
      Result :=  PItemIDList( PByte(FCIDA) + FCIDA^.aoffset[0])
  else
    Result := nil
end;

When compiling Embarcadero VirtualShellTools in Delphi 2007: http://embtvstools.svn.sourceforge.net/

function TShellIDList.InternalChildPIDL(Index: integer): PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
begin
  if Assigned(FCIDA) and (Index > -1) and (Index < PIDLCount) then
    Result := PItemIDList( PByte(FCIDA) 
                         + PDWORD(PByte(@FCIDA^.aoffset)
                                  +sizeof(FCIDA^.aoffset[0])*(1+Index))^)
  else
    Result := nil
end;

I get this error:

[Pascal Error] IDEVirtualDataObject.pas(1023): E2015 Operator not applicable to this operand type

What's the problem with this code and what kind of type-casting do I need to do to actually make it work?

I get the same error on the following (less complex) routine:

function TShellIDList.InternalParentPIDL: PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
begin
  if Assigned(FCIDA) then
      Result :=  PItemIDList( PByte(FCIDA) + FCIDA^.aoffset[0])
  else
    Result := nil
end;

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

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

发布评论

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

评论(2

热风软妹 2024-12-27 22:13:50

Pointermath 是在 Delphi 2009 中引入的。在 Delphi 2007 中您可以做的最好的事情就是使用 Inc 过程来代替:

function TShellIDList.InternalChildPIDL(Index: integer): PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
var
  Tmp, Tmp2: PByte;

begin
  if Assigned(FCIDA) and (Index > -1) and (Index < PIDLCount) then begin
    Tmp2:= PByte(@FCIDA^.aoffset);
    Inc(Tmp2, sizeof(FCIDA^.aoffset[0])*(1+Index));
    Tmp:= PByte(FCIDA);
    Inc(Tmp, PDWORD(Tmp2)^);
    Result := PItemIDList(Tmp);
  end
  else
    Result := nil
end;

Pointermath was introduced in Delphi 2009. The best you can do in Delphi 2007 is to use Inc procedure instead:

function TShellIDList.InternalChildPIDL(Index: integer): PItemIDList;
{ Remember PIDLCount does not count index [0] where the Absolute Parent is     }
var
  Tmp, Tmp2: PByte;

begin
  if Assigned(FCIDA) and (Index > -1) and (Index < PIDLCount) then begin
    Tmp2:= PByte(@FCIDA^.aoffset);
    Inc(Tmp2, sizeof(FCIDA^.aoffset[0])*(1+Index));
    Tmp:= PByte(FCIDA);
    Inc(Tmp, PDWORD(Tmp2)^);
    Result := PItemIDList(Tmp);
  end
  else
    Result := nil
end;
幽梦紫曦~ 2024-12-27 22:13:50

您还可以将 PByte 替换为 PAnsiChar

You could also replace PByte with PAnsiChar.

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