2011-08-22 25 views
6

嗨,大家好,我有一個奇怪的問題,我不知道我做錯了......問題的「中」在德爾福運營商

我有下面的代碼,請看看它的結束這就是它失敗我評論它...

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) 

,但我想知道我做錯了。

回答

12

一個集合是相同類型的值的集合。此類型必須是序數,並且此類型的變量必須具有最多256個可能的值。 (Official documentation)因此,一個集合不能包含整數,因爲有超過256個可能的整數。

您可以使用InRange功能:

if InRange(ep, tmp1, tmp2) then 

uses Math)。

+1

現在明白了,非常感謝! – opc0de

+2

@ opc0de:FWIW,我真的認爲編譯器應該說些什麼。至少,它應該給出警告...... –

+0

也許在未來的版本:)) – opc0de