即使在定义的时间间隔内,运算符也会失败"in"



我有一个奇怪的问题,我不知道我做错了什么

我有下面的代码。请看看它的结尾,这就是它失败的地方,我注释了它:

var
  IDH:PImageDosHeader;
  INH:PImageNtHeaders;
  ISH:PImageSectionHeader;
  buf:Pointer;
  FS:TFileStream;
  ep,tmp1,tmp2:DWORD;
  i:Word;
begin
  if OpenDialog1.Execute then
    begin
        FS:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead or fmShareDenyNone);
        GetMem(buf,FS.size);
        FS.Read(buf^,FS.Size);
        FS.Free;
        IDH:=PImageDosHeader(buf);
        INH:=PImageNtHeaders(DWORD(buf) + DWORD(IDH^._lfanew));
        ep:=INH^.OptionalHeader.AddressOfEntryPoint;
        for i:=0 to INH^.FileHeader.NumberOfSections - 1 do
        begin
          ISH:=PimageSectionHeader(DWORD(INH) + sizeof(TImageNtHeaders) + i * sizeof(TImageSectionHeader));
          tmp1:=ISH^.VirtualAddress;
          tmp2:=ISH^.VirtualAddress + ISH^.Misc.VirtualSize;
          ShowMessageFmt('%d -> %d .. %d',[ep,tmp1,tmp2]);
          if ep in [tmp1..tmp2] then ShowMessage('Got it'); //This fails even if ep is in the defined interval. Why?
        end;
    end;
end;

当然我可以用

替换这一行
if (ep>=tmp1) and (ep<=tmp2) 

但是我想知道我做错了什么

集合是相同类型的值的集合。此类型必须是有序的,并且此类型的变量必须最多有256个可能的值。(官方文档)因此,一个集合不能包含整数,因为有超过256个可能的整数。

你可以使用InRange函数:

if InRange(ep, tmp1, tmp2) then

(uses Math).

最新更新