![]() |
Re: class(TPersistent) - Zugriff auf "höhere" Proz
1. DANKE an alle die mir geholfen haben
2. Ich hab es jetzt geschafft.
Delphi-Quellcode:
unit TestOwner;
interface uses Windows, Messages, SysUtils, Classes, Controls, ExtCtrls; type TUnter = class(TPersistent) private FZahl : Integer; FOnChange : TNotifyEvent; procedure SetZahl(const Value: Integer); protected procedure Change; virtual; published property OnChange: TNotifyEvent read FOnChange write FOnChange; property Zahl : Integer read FZahl write SetZahl; end; type 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; FMain.OnChange := Upgrade; 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 } procedure TUnter.Change; begin if Assigned(FOnChange) then FOnChange(Self); end; procedure TUnter.SetZahl(const Value: Integer); begin FZahl := Value; Change; end; end. |
Re: class(TPersistent) - Zugriff auf "höhere" Proz
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. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz