initial conversion from Delphi to Pascal obj FPC