Why the composite component fails to parent controls?
        Posted  
        
            by lyborko
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by lyborko
        
        
        
        Published on 2010-04-19T18:49:14Z
        Indexed on 
            2010/04/20
            10:03 UTC
        
        
        Read the original article
        Hit count: 359
        
delphi
Hi,
I created my own Component : TPage , which Contains Subcomponent TPaper (TPanel). The problem is, that when I put controls such as TMemo or TButton on the TPaper (which fills up nearly whole area), the controls do not load at all. see example below
TPaper = class(TPanel)
  protected
      constructor Create(AOwner: TComponent);override;
      destructor Destroy;override;
  public
      procedure Paint; override;
  end;
TPage = class(TCustomControl)
   private
      FPaper:TPaper;
   protected
      procedure CreateParams(var Params:TCreateParams); override;
   public
      constructor Create(AOwner: TComponent);override;
      destructor Destroy;override;
   published
      property Paper: TPaper read FPaper write FPaper;
   end;
constructor TPage.Create(AOwner: TComponent);
  begin
  inherited Create(AOwner);
  PaperOrientation:=poPortrait;
  PaperSize:=psA4;
  PaperBrush:=TBrush.Create;
  PaperBrush.Color:=clWhite;
  PDFDocument:=Nil;
  FPaper:=TPaper.Create(Self);
  FPaper.Parent:=Self;
  FPaper.SetSubComponent(True);
  end;
... Memo1 is parented in TPaper (TPanel) at design-time, but after pressing "Run" it does not exist.
procedure TForm1.btn1Click(Sender: TObject);
begin
if not Assigned(Memo1) then ShowMessage('I do not exist');   //Memo1 is nil
end;
Have you any idea what's wrong?
Thanks a lot
P.S Delphi 7
When I put TMemo inside TPaper and save the unit (Unit1), after inspection of associated dfm file, there is no trace of TMemo component. (Thats why it can not load to app.)
© Stack Overflow or respective owner