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