I owned for years, and still do, the Canon 20D. I recently upgraded to the Canon 550D. I have the 24-105 L lens. I do not regret my camera upgrade one bit.
For about a month I considered the 7D, but decided that for my needs - essentially a keen amateur of landscapes I had no need for the features of the 7D. I also looked at the 60D, but found that it didn't have very good write ups, so I went for the 550D, which seemed to be excellently recieved all round. Yes the 550D takes SD cards, wheras the 20D was compact flash, but with storage the price it is, it was not a problem.
What you have to remember is the camera is really just a capture device, like a sophisticated hard drive. If you shoot RAW then all the information will be captured and it is up to you to take it out and post process. This is where good glass comes in essential. In other words don't spend money on an expensive camera and buy cheap glass to put in front of it. The better the lens, the sharper, more tonal range the pictures will have.
My advice then is if you want to upgrade don't sell your L lens - you will regret it. Sell the 40D and buy a new camera with the proceeds, but don't be bowled over by features you will never use.