How to encode objects of unknown type?

Thanks a lot, this works now. I have to admit though, that I don't understand why and how.

Is there a place where I can read up on existentials and this topic?