Recent

Author Topic: (SOLVED)Unit1 and Unit2 and records problem  (Read 223 times)

JLWest

  • Hero Member
  • *****
  • Posts: 934
(SOLVED)Unit1 and Unit2 and records problem
« on: September 11, 2020, 10:22:05 pm »
I get a compiler error at line 12 in Unit2 of {<===Error Identifier not found} I read a post on this subject and the ref manual but something is wrong.

Thanks.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, Forms, Controls, Graphics,
  7.   Dialogs, StdCtrls, Unit2;  {Note}
  8.  
  9. type
  10.     TRCD = record
  11.      name : string;
  12.     end;
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Button1: TButton;
  18.     Label1: TLabel;
  19.  
  20.   procedure Button1Click(Sender: TObject);
  21.   procedure GetName;
  22.   private
  23.   public
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.   RCD : TRCD;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. procedure TForm1.GetName;
  35.  Var AName : String;
  36.  begin
  37.   AName := FillName(AName);
  38.   Label1.Caption := AName;
  39.  end;
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.   GetName;
  44. end;
  45.  
  46. end.
  47.  

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10.  
  11.  
  12. function FillName(ARCD : TRCD) : TRCD;             {<===Error Identifier not found}
  13. function FillName(ASTRING : String) : String;
  14.  
  15. implementation
  16.  uses Unit1;
  17.  
  18.  function FillName(ASTRING : String) : String;
  19.   begin
  20.     Result := 'John Doe';
  21.   end;
  22.  
  23.  function FillName(ARCD : TRCD) : TRCD;
  24.   Var RCD : TRCD;
  25.   begin
  26.     RCD := ARCD;
  27.     Result := RCD.name := 'John Doe';
  28.   end;
  29.  
  30. end.
  31.  
« Last Edit: September 11, 2020, 11:13:55 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Bi0T1N

  • Jr. Member
  • **
  • Posts: 50
Re: Unit1 and Unit2 and records problem
« Reply #1 on: September 11, 2020, 10:33:30 pm »
You need to include Unit1 in Unit2 and not the other way around. The type is defined in Unit1 so you've to tell Unit2 about it by adding it to the uses clause.
« Last Edit: September 11, 2020, 10:35:12 pm by Bi0T1N »

JLWest

  • Hero Member
  • *****
  • Posts: 934
Re: Unit1 and Unit2 and records problem
« Reply #2 on: September 11, 2020, 11:13:15 pm »
Thanks , it worked
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018