How to clear the graphics in a TImage control

A short Delphi code block saves the day

Delphi programmers use the TImage control to display an image -- files that end in extensions including ICO, BMP, WMF, WMF, GIF and JPG. The Picture property specifies the image that appears in the TImage control. Delphi supports several different methods for assigning an image for the TImage component: a TPicture's method LoadFromFile reads graphics from disk or the Assign method obtains the image from Clipboard, for example.

In the absence of a direct command to clear the Picture property, you'll need to assign a "nil" object to it. Doing so essentially blanks the image.

For a TImage control named Photo, use either of two methods to clear the assigned graphic:

Photo.Picture := nil;



Either code block will clear the picture from your TImage control. The first approach asserts a nil value to the Picture property; the second approach assigns a nil through the use of a method. 

» How to add leading zero's to a number