The D300 is a substantially more capable camera than the 40D, but such a mismatch is inevitable in making comparisons. Rarely do you have equally-matched cameras in the two lineups. When comparing the 40D, look at the specs and features of the D80, D90, D200, and D300 and make up your own mind as to what the pros/cons of each are.
Always keep the price differences in mind... usually the "better" camera also costs more, so you want to create your own perception of value and bang-for-the-buck and use that as your primary metric. Finally, also keep age of the item in mind: older items tend to cost less due to depreciation and the advent of newer technology in competing products. Not fair to compare X item released in 2008 with Y competitor released in 2006 without keeping that fact in mind.