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:


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.

Monday, April 07, 2014

Short tips: PNGImage

If you have problems processing PNG images because you are using DevExpress components, add this to the beginning of your program’s uses list:


DevExpress registers PNG handler with doesn’t behave exactly the same as Delphi’s built-in TGraphics descendants. With this addition, PNGImage.RegisterFileFormat will be called after dxGDIPlusClasses.RegisterFileFormat and will overwrite DevExpress’ PNG handler.