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