This can be a bit confusing.
When you vote in many states, you are voting for a candidate as well as any delegates to be sent to the party convention. What's weird here is that these people tell you whom they support beforehand. These people are called pledged delegates
Pledged delegates in the Democratic Party are required to express a preference for either one of the party’s presidential candidates or an uncommitted preference as a condition of their selection. Under current party rules, delegates pledged to a specific candidate are encouraged—but not required—to vote for the candidate they had been selected to support.
So, yes, you could vote for Obama, and then vote for a delegate who supports Clinton. And that person could vote for Clinton if they wanted to. If you think that's complicated the actual rules are even stranger
What is a pledged delegate? A pledged delegate is a delegate allocated to a candidate based on his or her performance in a caucus or primary. The campaigns have the ability to vet these delegates and can even submit a list of names to represent them.
Simple enough, right? Wrong!
2,591 district-level pledged delegates – Not all pledged delegates are selected in the same way. There are state-level delegates and district-level delegates. Most district-level delegates are determined at either a congressional district or state legislative district level.
1,388 state-level pledged delegates – The rest of the pledged delegates, 1,388 of them, are awarded at the state level. And there are two kinds of state-level delegates:
“Pledged Party Leader and Elected Officials (PLEO)” delegates. These are high-ranking elected officials, like big-city mayors, who get to be delegates at the convention. They’re pledged proportionally to the top performers in their states.
At-large pledged delegates, who are selected by the state party. If a candidate drops out of the race after winning state-wide delegates, their sate-level at-large pledged delegates are redistributed among the remaining viable candidates. All the state-level pledged delegates won by Mike Bloomberg, Pete Buttigieg, Amy Klobuchar and Elizabeth Warren, for instance, could be doled out to Bernie Sanders and Joe Biden, depending on results in a particular state.
And that's avoiding other primary wackiness like caucuses, superdelegates, etc. The Republican rules are almost as loose, but vary from state-to-state.