An example:
Application project with a "unit1" that contains "Form1", a "Memo1", and "uses unit2".
A "unit2" (no forms) with a "procedure writetomemo"
How can I have the "unit2" procedure to write to the memo1 in unit1?
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, unit2;
type
{ TForm1 }
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
unit2.writetomemo();
end;
end.
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
procedure writetomemo;
implementation
procedure writetomemo;
begin
memo1.text := 'hi';
end;
end.
I get error:
unit2.pas(17,8) Error: Identifier not found "memo1"
unit2.pas(22) Fatal: There were 1 errors compiling module, stopping