Syntax rules for the procedural "units" of Lazarus Pascal

I organize the source code of the application in a Pascal compilation. Units Using File -> New Unit

The following module compiles OK ...

 unit CryptoUnit; {$mode objfpc}{$H+} interface function Encrypt(key, plaintext:string):string; function Decrypt(key, ciphertext:string):string; implementation uses Classes, SysUtils, Blowfish; function Encrypt(key, plaintext:string):string; ... 

However, this has compilation errors, since it cannot identify the β€œException” on line 6 ...

 unit ExceptionUnit; {$mode objfpc}{$H+} interface procedure DumpExceptionCallStack(E: Exception); // <--- problem implementation uses Classes, SysUtils, FileUtil; { See http://wiki.freepascal.org/Logging_exceptions } procedure DumpExceptionCallStack(E: Exception); ... 

If I assume that an Exception is defined in SysUtils (how can I say?), I cannot put uses SysUtils before the interface (the compiler complains that it was expecting an interface )

How to tell the compiler that Exception defined in SysUtils ?

+6
source share
1 answer

Other units that are used by your device should be indicated after the interface keyword, but before other operations in the interface section.

Your example should work in the following form:

 unit ExceptionUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil; procedure DumpExceptionCallStack(E: Exception); implementation { See http://wiki.freepascal.org/Logging_exceptions } procedure DumpExceptionCallStack(E: Exception); 
+6
source

Source: https://habr.com/ru/post/952378/


All Articles