Search code examples
delphidelphi-7

uses and procedure syntax errors


I was trying to understand how to use units in my main 'modules test unit'. they are 'module1.pas', and 'module2.pas'. This is a console program and I would like for both units to be displayed and used in my main unit modules_test:

program modules_test;

uses
  SysUtils, module1, module2;

procedure modules_display;
begin
  module1;
  module2;
end;

end. 

here's unit module1:

unit module1;

interface

uses
  Classes, SysUtils;

implementation

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

end.

And module2:

unit module2;

interface

uses
  Classes, SysUtils;

implementation

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

end.

As I'm fairly certain that I'm missing a few things, as well as the errors I get, what would I need to use for this to execute properly?


Solution

  • 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.
    

    See some documentation, Programs and Units.