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