Your entry is a managed entry. Therefore, it must be initialized. Your code uses GetMemone that does not initialize the record. You should use instead New. Replace
GetMem(P, SizeOf(TRec));
from
New(P);
Similarly, when you need to free yourself, you must complete the recording. Use Dispose, not FreeMem.
, - . :
// allocate and initialize
GetMem(P, SizeOf(P^));
Initialize(P^);
// finalize and deallocate
Finalize(P^);
FreeMem(P);