指针算术在D2007我如何使它工作



在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错误]IDEVirtualDataObject.pas(1023): E2015 Operator不适用于此操作数类型

这段代码的问题是什么?我需要做什么样的类型转换才能使它实际工作?

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

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;

指针数学是在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;

也可以用PAnsiChar代替PByte

最新更新