The Doctor goes onto the holodeck and a kenoplasmic radiation surge disrupts his memory core. He experiences an elaborate delusion and is eventually saved by the crew. Only we see the whole thing from his point of view, where his delusion of Reg Barclay of all people convinces himself that he's a human being. Wasn't this a Barclay ep called "Ship in a Bottle"?
On an interesting side note, Reg Barclay was responsible for testing Doc's interpersonal skills. So you assign someone who has no interpersonal skills to test the interpersonal skills on a hologram that shouldn't need any - but really really does need them? Interesting choice.
"Computer, delete Paris."
- The Doctor