【问题标题】:Syntax rules for Lazarus Pascal procedural "Units"Lazarus Pascal 程序“单位”的语法规则
【发布时间】:2013-08-23 16:52:40
【问题描述】:

我使用 File -> New Unit 将我的应用程序的源代码组织到 Pascal 编译单元中

下面的单元编译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; 
...

但是这个有编译错误,因为它无法在第 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);      
...

如果我假设Exception 是在SysUtils 中定义的(我怎么知道?)我不能把uses SysUtils 放在interface 之前(编译器抱怨它期待interface

如何告诉编译器Exception 是在SysUtils 中定义的?

【问题讨论】:

  • 我认为您需要将uses SysUtils 行紧跟在interface 行之后(即不在它之前)。

标签: syntax lazarus


【解决方案1】:

您的单元使用的其他单元将在 interface 关键字之后引用,但在 interface 部分中的其他语句之前。

您的示例应采用以下形式:

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); 

【讨论】:

    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多