[Lazarus] OOP basics - 2
Kjow
antispammoni at gmail.com
Wed Apr 14 17:04:15 CEST 2010
2010/4/14 Michael Van Canneyt <michael at freepascal.org>:
>
> Put unit2 in the implementation uses list of unit1. Then it should work.
Other question:
if I have a similar situation, it is possible to implement?
____________________
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics,
Dialogs, unit3;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
x,y: integer;
tester1: TTest;
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
init(5, 2, Form1);
ShowMessage('Result: '+IntToStr(tester1.test(x,y,Form1)));
end;
end.
____________________
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, unit1, unit3;
procedure init(a,b: integer; MainForm: TForm1);
implementation
var
tester2: TTest;
procedure init(a,b: integer; MainForm: TForm1);
begin
MainForm.x:=tester2.test(a,b,MainForm);
MainForm.y:=-tester2.test(-a,-b,MainForm);
end;
end.
____________________
unit Unit3;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, unit1;
Type
TTest = class
a: byte;
b: byte;
function test(c,d: integer; MainForm: TForm1): integer;
end;
implementation
function TTest.test(c,d: integer; MainForm: TForm1): integer;
begin
Result:=c+d+MainForm.x+MainForm.y;
end;
end.
____________________
I changed the 3rd unit, so now it returns:
unit3.pas(8,27) Fatal: Circular unit reference between Unit3 and Unit1
Thanks!
Kjow
More information about the Lazarus
mailing list