Wieso willst du denn einen "published" Event "OnChange" machen, wenn du ihn direkt wieder belegst. Folgende Zeilen sollten dein Problem auch lösen (nicht getestet). Wie gesagt, wenn du alles unter
ein type schreibst, dann kannst du "TTestOwner" forward deklarieren.
Delphi-Quellcode:
unit TestOwner;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls;
type
TTestOwner =
class;
TUnter =
class(TPersistent)
private
FOwner: TTestOwner;
FZahl : Integer;
procedure SetZahl(
const Value: Integer);
protected
procedure Change;
virtual;
public
constructor Create(AOwner: TTestOwner);
property Owner : TTestOwner
read FOwner;
published
property Zahl : Integer
read FZahl
write SetZahl;
end;
TTestOwner =
class(TPaintbox)
private
{ Private declarations }
FMain : TUnter;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure Upgrade(Sender: TObject);
published
{ Published declarations }
property Main : TUnter
read FMain
write FMain;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
My Own', [TTestOwner]);
end;
{ TTestOwner }
constructor TTestOwner.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMain := TUnter.Create(Self);
end;
destructor TTestOwner.Destroy;
begin
FMain.Free;
inherited Destroy;
end;
procedure TTestOwner.Upgrade(Sender: TObject);
begin
Self.Canvas.TextOut(Self.FMain.FZahl,1,'
Hallo');
end;
{ TUnter }
constructor TUnter.Create(AOwner: TTestOwner);
begin
inherited Create;
FOwner := AOwner;
end;
procedure TUnter.Change;
begin
FOwner.Upgrade;
end;
procedure TUnter.SetZahl(
const Value: Integer);
begin
if Value <> FZahl
then
begin
FZahl := Value;
Change;
end;
end;
end.