When I was camera shopping, I used http://www.dpreview.com/reviews/compare.asp to get an idea what was available. I ultimately decided on a Pentax K10D; but only after comparing it to the Nikon D80, Canon Rebel XTi, Sony A100, and Olympus E-510.
In comparison to the Nikon D40, I'd start by looking at the Pentax K100D, Pentax K110D, Samsung GX-1S, Samsung GX-10, Olympus E-300, Olympus E-330, Olympus E-410, Olympus E-500, Canon Digital Rebel XT and XTi, and Sony A100.
And what about the Nikon D40x?
Yikes, there are too many choices...
Lastly, I went in to a local camera shop to see/feel each of them in my hands and ultimately bought it locally.