Different in every state I think, but in the caucuses people seem to get picked as delegates on the day of the caucus. A lot of them go to the state convention, and a subgroup is “picked” to go to the national convention. I don’t know if they’re picked by the candidates or by the state party. This thread explains how Ron Paul people are executing a plan to stack the delegates with their own people:
http://freerepublic.com/focus/f-news/2843327/posts
In Pennsylvania, you have to run on a ballot to be elected as a delegate and you can vote for whoever you want at the convention. It doesn’t have to be who won the primary in your state.
I've always wondered how some of the Dem delegates afford it. I bet the party pays for some of them... churches pay for others. I wonder!