unit RzPnlPnl; interface usesSysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, ExtCtrls; typeTSubPanel = class(TPanel)protectedprocedure ReadState( Reader : TReader ); override;end; TPanelPanel = class(TPanel)privateFSubPanel : TSubPanel;protectedprocedure WriteComponents( Writer : TWriter ); override;procedure ReadState( Reader : TReader ); override;publicconstructor Create( AOwner : TComponent ); override;end; procedure Register; implementation procedure TSubPanel.ReadState( Reader : TReader );varOldOwner: TComponent;beginOldOwner := Reader.Owner; { Сохраняем старого владельца, что необходимо для PanelPanel }Reader.Owner := Reader.Root; { Задаем в качестве владельца форму }tryinherited ReadState(Reader);finallyReader.Owner := OldOwner;end;end; constructor TPanelPanel.Create( AOwner : TComponent );constRegistered: Boolean = False;begininherited Create( AOwner ); FSubPanel := TSubPanel.Create( Self );FSubPanel.Parent := Self;FSubPanel.SetBounds( 20, 20, 200, 100 );FSubPanel.Name := 'SomeName'; if not Registered thenbeginClasses.RegisterClasses([TSubPanel]); { так TSubPanel может храниться в файле формы }Registered := True;end; end; procedure TPanelPanel.ReadState( Reader : TReader );varOldOwner: TComponent;I: Integer;beginfor I := 0 to ControlCount - 1 doControls[ 0 ].Free; OldOwner := Reader.Owner;Reader.Owner := Self; {Для чтения субкомпонентов, установите данный экземпляр в качестве родителя}tryinherited ReadState(Reader);finallyReader.Owner := OldOwner;end;end; procedure TPanelPanel.WriteComponents( Writer : TWriter );varI: Integer;beginfor I := 0 to ControlCount - 1 doWriter.WriteComponent(Controls[I]);end; procedure Register;beginRegisterComponents( 'Samples', [ TPanelPanel ] );end; end. |
- Ray Konopka [000947]