Index: components/codetools/directorycacher.pas
===================================================================
--- components/codetools/directorycacher.pas	(revision 12385)
+++ components/codetools/directorycacher.pas	(working copy)
@@ -622,17 +622,13 @@
     while r>=l do begin
       m:=(l+r) shr 1;
       CurFilename:=@FListing.Names[FListing.NameStarts[m]];
-      case FileCase of
-      ctsfcDefault:
-        {$IFDEF CaseInsensitiveFilenames}
-        cmp:=stricomp(PChar(Pointer(ShortFilename)),CurFilename);// pointer type cast avoids #0 check
-        {$ELSE}
-        cmp:=strcomp(PChar(Pointer(ShortFilename)),CurFilename);
-        {$ENDIF}
-      ctsfcAllCase,ctsfcLoUpCase:
-        cmp:=stricomp(PChar(Pointer(ShortFilename)),CurFilename);
-      else RaiseDontKnow;
-      end;
+      // Tobias Giesen 2007-10-08: we MUST use the same 
+      // comparison function that was used for sorting the list.
+      // We cannot take any additional options into account within 
+      // the binary search, because the list has been sorted in a 
+      // certain way which we must follow. 
+      // Otherwise, files will not be found in all cases.
+      cmp:=ComparePCharFirstCaseInsThenCase(PChar(Pointer(ShortFilename)),CurFilename);// pointer type cast avoids #0 check
       if cmp>0 then
         l:=m+1
       else if cmp<0 then
@@ -674,7 +670,10 @@
     while r>=l do begin
       m:=(l+r) shr 1;
       CurFilename:=@FListing.Names[FListing.NameStarts[m]];
-      cmp:=stricomp(PChar(Pointer(UnitName)),CurFilename);
+      // Tobias Giesen 2007-10-08: we MUST use the same 
+      // comparison function that was used for sorting the list.
+      // Otherwise, files will not be found in all cases.
+      cmp:=ComparePCharFirstCaseInsThenCase(PChar(Pointer(UnitName)),CurFilename);
       if cmp>0 then
         l:=m+1
       else if cmp<0 then
@@ -683,17 +682,9 @@
         break;
     end;
     // now all files above m are higher than the Unitname
-    // -> check that m is equal or above = find lowest
+    // -> check that m is equal or above
     if (Cmp>0) then
-      inc(m)
-    else if (Cmp=0) then begin
-      while (m>0) do begin
-        CurFilename:=@FListing.Names[FListing.NameStarts[m-1]];
-        cmp:=stricomp(PChar(Pointer(UnitName)),CurFilename);
-        if cmp<>0 then break;
-      end;
-    end;
-      
+      inc(m);
     // now all files below m are lower than the Unitname
     // -> now find a filename with correct case and extension
     while m<FListing.NameCount do begin
