Lazarus: fatal error when opening an "output" procedure in another procedure

46 views Asked by At

So I just worked on a generic program for school which uses the sort algorithms. The teacher always loves putting everything into different units so I decided to create an "output" procedure which gives an output of the sorted array.

unit selectionsort;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, typen, ausgabe;
procedure SSort (FeldS: t_Feld);

implementation
procedure SSort (FeldS: t_Feld);
var h,j,min,hilf: integer;
begin
  for h:= 1 to c-1 do
      begin
        ## all the sorting stuff
      end;
  **ausgabe(FeldS);**
end;
end.

(ausgabe is german for output)

unit ausgabe;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, typen;
procedure ausgabe(FeldA: t_feld);

implementation
procedure ausgabe(FeldA: t_feld);
begin
    for i:= 1 to c do
      begin
        write(FeldA[i], ' ');
      end;

  readln();
end;

end.

The bold part (when calling the procedure ausgabe) is where I get the error: fatal: Syntax error, "." expected but "(" found. I know I could just delete the procedure "Ausgabe" and do the output in the sort procedures but I would like to do it this way.

1

There are 1 answers

1
FPK On BEST ANSWER

As the procedure ausgabe and the unit have the same name (this is possible as they are in different scopes), the compiler assume a so-called "qualified identifier": unitname.procedurename. This is needed if multiple units have identifiers with the same name. To overcome the error: Either you rename the unit or the procedure or you call the procedure using its qualified name (the first ausgabe is the name of the unit where the compiler should search for the symbol, the second ausgabe is the actual procedure name):

ausgabe.ausgabe(FeldS);