使用和过程语法错误

时间:2015-07-09 22:23:33

标签: delphi delphi-7

我试图了解如何在我的主要“模块测试单元”中使用单元。它们是'module1.pas'和'module2.pas'。 这是一个控制台程序,我希望在我的主单元modules_test中显示和使用这两个单元:

program modules_test;

uses
  SysUtils, module1, module2;

procedure modules_display;
begin
  module1;
  module2;
end;

end. 

这里是unit module1:

unit module1;

interface

uses
  Classes, SysUtils;

implementation

begin
  writeln('this is module 1....');

end.

和module2:

unit module2;

interface

uses
  Classes, SysUtils;

implementation

begin
  writeln('this is module 2....');

end.

由于我很确定我缺少一些东西,以及我得到的错误,我需要使用什么才能正确执行?

1 个答案:

答案 0 :(得分:4)

program modules_test;

{$APPTYPE CONSOLE}

uses 
  SysUtils, module1, module2;

procedure modules_display;
begin
  module1.Test;  // Fully qualify the name of the procedure
  module2.Test;
end;

begin
  modules_display;
  ReadLn;
end. 
unit module1;

interface

// Declare a procedure that can be called from outside of this unit
procedure Test;  

implementation

uses
  // Unit references that are exclusively used in the implementation section
  Classes, SysUtils; 

// This is the implementation of the procedure
procedure Test;
begin
  writeln('this is module 1....');
end;

end.
unit module2;

interface

// Declare a procedure that can be called from outside of this unit
procedure Test;

implementation

uses
  // Unit references that are exclusively used in the implementation section
  Classes, SysUtils;

// This is the implementation of the procedure
procedure Test;
begin
  writeln('this is module 2....');
end;

end.

请参阅一些文档Programs and Units