Showing posts with label short tips. Show all posts
Showing posts with label short tips. Show all posts

Saturday, April 12, 2014

Safe-casting Pointers

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.