Replace delphi mode with objfpc mode and fix up code accordingly