Delphi:
"Code Contracts" Not Supported
Delphi does not offer built-in Design by Contract features. It does offer an Assert method which tests if an expression is true. If false, an EAssertionFailed exception is raised. Although you can use Assert in a similar manor as you would use a pre-condition contract, the Delphi help clearly says Assert is a debugging tool only and to not use it in production code. //Although not intended as a code contract feature, //Assert is useful for debugging. method Cyborg.Walk(pPace); begin Assert(pPace > 0); Assert(pPace < 100); //Overloaded version with message. Assert(FEnergyLevel >= 10, 'Energy level too low.'); end;
|