what could possibly go wrong??
That example should work fine.
That's because you create something in memory and copy the pointer to another pointer.
The first example you had, you had a variable which disapears after the procedure and your pointer is hanging. In this example the pointer still points to some memory thats created and not released. So perfectly fine.
BTW. Your original second example with psock only went wrong because you had a pointer to a pointer of which the first pointer went away after the procedure. If you did a psock := sock it would have worked (that's what i did in my example but as a function result).
You really need to realize that TLUDPL is a class and variables of classes are just pointers to an instance of that class. So sock := TLUDPL.Create will create a pointer to a TLUDPL instance. It's redundant to create a pointer to Sock because Sock is already a pointer. So doing pSock := Sock would have worked because although Sock, as pointer itself, is destroyed, the memory where it points to wasn't released and pSock would have still been valid. But doing pSock := @Sock (which you did) was wrong because that points to a pointer (which is a pointer itself) which will be destroyed after the procedure.
I hope I explained this a bit clearly
Eventually you will continue to work more and more with procedures and functions and finally you will also grasp the notion of classes
There was a website which goes over the basics of object pascal.
Maybe it's some interesting reading for you.
Modern Object Pascal Introduction for Programmers