written for http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_24010758.html check the discussion for more details