Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax rules for Lazarus Pascal procedural "Units"

Tags:

syntax

lazarus

I organise my app's source code into Pascal compilation Units using File -> New Unit

The following Unit 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 one has compilation errors as it can't identify "Exception" at 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 Exception is defined in SysUtils (how can I tell?) I can't put uses SysUtils before interface (the compiler complains it was expecting interface)

How do I tell the compiler that Exception is defined in SysUtils?

like image 767
RedGrittyBrick Avatar asked Aug 23 '13 16:08

RedGrittyBrick


Video Answer


1 Answers

Other units that are used used by your unit are to be referenced after the interface keyword, but before other statements 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); 
like image 82
jwdietrich Avatar answered Nov 08 '22 22:11

jwdietrich