You cannot safe-cast a pointer. This will fail:
ptr as TProject
You can only cast pointers the unsafe way:
TProject(ptr)
That is, unless you use this neat trick:
TObject(ptr) as TProject
This will also catch programming errors, specifically a pointer that doesn’t point to an object.