Його/її/їх vs. нього/неї/них

While trying to master Ukrainian pronouns in all the different cases, I came across some places that said that його, її, and їх turned into нього/неї/них in some cases. Would somebody be able to give some more specific examples of when to use the second set of 3rd person pronouns, as well as some more general examples of pronouns in different cases?

Ми спитали його - we asked him;
я запросив її на побачення - I invited her on a date;
я спитав їх котра година - I asked them what time it is now.

When його/її/їх are used with a preposition, they change to нього/неї/них:

Я прийшов до нього - I came to him;
Пісня про неї - a song about her;
Я хвилююся за них - I worry for them.

This does not apply, however, when його/її/їх function as possessive pronouns, e.g. в його руках (in his hands), до її батьків (to her parents), as the preposition applies to the noun, and not to the possessive pronoun.

Hello! Just wanted to point out that for "somebody has something" you can also use structure with actual word "to have" - "мати".
For example,
Він має машину - He has a car
Вона має сукню - She has a dress
Вони мають цуценят - They have puppies.

I think його/її/ їх is used either to indicate that person possess something or person is a direct object of verb. Нього/неї/них is used when persons are indirect objects of verbs. In both Ukrainian and English prepositions are placed before indirect objects, as it was mentioned by Parubok.