Delphi basic algorithm