Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Control '' has no parent window

TataL_LoRTataL_LoR Member Posts: 13
Hi

I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".

Please help

TataL_LoR

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi
    :
    : I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".
    :
    : Please help
    :
    : TataL_LoR
    :
    Only TForms can be placed directly on the screen all other controls must be placed inside something (such as a form or another control). If you want to create a titleless form, then set the BorderStyle to bsNone. If you want to show it without losing focus on another control, you can call the Show() method.
  • TataL_LoRTataL_LoR Member Posts: 13
    : : Hi
    : :
    : : I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".
    : :
    : : Please help
    : :
    : : TataL_LoR
    : :
    : Only TForms can be placed directly on the screen all other controls must be placed inside something (such as a form or another control). If you want to create a titleless form, then set the BorderStyle to bsNone. If you want to show it without losing focus on another control, you can call the Show() method.
    :

    I'm placing this control in a form

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    postIt := TPostIt.Create(Self);
    postIt.Top := 1;
    postit.Left := 1;
    postit.OnPaint := FormPaint;
    end;

    procedure TForm1.FormShow(Sender: TObject);
    begin
    postIt.FileName := 'p2.bmp';
    postIt.Caption := 'postIt';
    end;

    This doesn't do anything. I also tried calling the Paint method in the TPostIt class, but this raises the exception I mentioned, Control '' has no parent window.

    TPostIt = class(TGraphicControl)
    private
    FBitmap: TBitmap;
    FFileName: TFileName;
    ...
    published
    property FileName: TFileName read FFileName write SetFileName;
    ...
    end;

    procedure TPostIt.SetFileName(Value: TFileName);
    begin
    FFileName := Value;
    Bitmap.LoadFromFile(FileName);

    Paint; //if I call Repaint here, it doesn't do anything
    end;

    I think that it has something to do with the handle of the component which is not assigned or something. But I'm not sure what that means or how to solve this issue.
  • zibadianzibadian Member Posts: 6,349
    : : : Hi
    : : :
    : : : I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".
    : : :
    : : : Please help
    : : :
    : : : TataL_LoR
    : : :
    : : Only TForms can be placed directly on the screen all other controls must be placed inside something (such as a form or another control). If you want to create a titleless form, then set the BorderStyle to bsNone. If you want to show it without losing focus on another control, you can call the Show() method.
    : :
    :
    : I'm placing this control in a form
    :
    : procedure TForm1.FormCreate(Sender: TObject);
    : begin
    : postIt := TPostIt.Create(Self);
    [red]PostIt.Parent := Self;[/red]
    : postIt.Top := 1;
    : postit.Left := 1;
    : postit.OnPaint := FormPaint;
    : end;
    :
    : procedure TForm1.FormShow(Sender: TObject);
    : begin
    : postIt.FileName := 'p2.bmp';
    : postIt.Caption := 'postIt';
    : end;
    :
    : This doesn't do anything. I also tried calling the Paint method in the TPostIt class, but this raises the exception I mentioned, Control '' has no parent window.
    :
    : TPostIt = class(TGraphicControl)
    : private
    : FBitmap: TBitmap;
    : FFileName: TFileName;
    : ...
    : published
    : property FileName: TFileName read FFileName write SetFileName;
    : ...
    : end;
    :
    : procedure TPostIt.SetFileName(Value: TFileName);
    : begin
    : FFileName := Value;
    : Bitmap.LoadFromFile(FileName);
    :
    : Paint; //if I call Repaint here, it doesn't do anything
    : end;
    :
    : I think that it has something to do with the handle of the component which is not assigned or something. But I'm not sure what that means or how to solve this issue.
    :
    The Parent property is different from the Owner property and must be set separately (See above). The Owner property determines which object handle freeing the component (usually the form or datamodule), while the Parent handles repaints, TabOrder, and is only applicable to controls.
  • TataL_LoRTataL_LoR Member Posts: 13
    : : : : Hi
    : : : :
    : : : : I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".
    : : : :
    : : : : Please help
    : : : :
    : : : : TataL_LoR
    : : : :
    : : : Only TForms can be placed directly on the screen all other controls must be placed inside something (such as a form or another control). If you want to create a titleless form, then set the BorderStyle to bsNone. If you want to show it without losing focus on another control, you can call the Show() method.
    : : :
    : :
    : : I'm placing this control in a form
    : :
    : : procedure TForm1.FormCreate(Sender: TObject);
    : : begin
    : : postIt := TPostIt.Create(Self);
    : [red]PostIt.Parent := Self;[/red]
    : : postIt.Top := 1;
    : : postit.Left := 1;
    : : postit.OnPaint := FormPaint;
    : : end;
    : :
    : : procedure TForm1.FormShow(Sender: TObject);
    : : begin
    : : postIt.FileName := 'p2.bmp';
    : : postIt.Caption := 'postIt';
    : : end;
    : :
    : : This doesn't do anything. I also tried calling the Paint method in the TPostIt class, but this raises the exception I mentioned, Control '' has no parent window.
    : :
    : : TPostIt = class(TGraphicControl)
    : : private
    : : FBitmap: TBitmap;
    : : FFileName: TFileName;
    : : ...
    : : published
    : : property FileName: TFileName read FFileName write SetFileName;
    : : ...
    : : end;
    : :
    : : procedure TPostIt.SetFileName(Value: TFileName);
    : : begin
    : : FFileName := Value;
    : : Bitmap.LoadFromFile(FileName);
    : :
    : : Paint; //if I call Repaint here, it doesn't do anything
    : : end;
    : :
    : : I think that it has something to do with the handle of the component which is not assigned or something. But I'm not sure what that means or how to solve this issue.
    : :
    : The Parent property is different from the Owner property and must be set separately (See above). The Owner property determines which object handle freeing the component (usually the form or datamodule), while the Parent handles repaints, TabOrder, and is only applicable to controls.
    :
    Thank you very much, that solves the problem. But there is just one more thing... is there any way of embedding this part in the constructor by converting owner to TWinControl? or do I need a new constructor with 2 parameters, of which one should be a control(the parent) and the other a component(the owner)?

    Thanks again
    TataL_LoR
  • zibadianzibadian Member Posts: 6,349
    : : : : : Hi
    : : : : :
    : : : : : I'm trying to extend the TGraphicControl class to make a post-it like component. There is a problem when I call Repaint, it doesn't do anything. If I call Paint directly from within the class (in a SetBitmap method, for example) an exception pops up with the message "Control '' has no parent window".
    : : : : :
    : : : : : Please help
    : : : : :
    : : : : : TataL_LoR
    : : : : :
    : : : : Only TForms can be placed directly on the screen all other controls must be placed inside something (such as a form or another control). If you want to create a titleless form, then set the BorderStyle to bsNone. If you want to show it without losing focus on another control, you can call the Show() method.
    : : : :
    : : :
    : : : I'm placing this control in a form
    : : :
    : : : procedure TForm1.FormCreate(Sender: TObject);
    : : : begin
    : : : postIt := TPostIt.Create(Self);
    : : [red]PostIt.Parent := Self;[/red]
    : : : postIt.Top := 1;
    : : : postit.Left := 1;
    : : : postit.OnPaint := FormPaint;
    : : : end;
    : : :
    : : : procedure TForm1.FormShow(Sender: TObject);
    : : : begin
    : : : postIt.FileName := 'p2.bmp';
    : : : postIt.Caption := 'postIt';
    : : : end;
    : : :
    : : : This doesn't do anything. I also tried calling the Paint method in the TPostIt class, but this raises the exception I mentioned, Control '' has no parent window.
    : : :
    : : : TPostIt = class(TGraphicControl)
    : : : private
    : : : FBitmap: TBitmap;
    : : : FFileName: TFileName;
    : : : ...
    : : : published
    : : : property FileName: TFileName read FFileName write SetFileName;
    : : : ...
    : : : end;
    : : :
    : : : procedure TPostIt.SetFileName(Value: TFileName);
    : : : begin
    : : : FFileName := Value;
    : : : Bitmap.LoadFromFile(FileName);
    : : :
    : : : Paint; //if I call Repaint here, it doesn't do anything
    : : : end;
    : : :
    : : : I think that it has something to do with the handle of the component which is not assigned or something. But I'm not sure what that means or how to solve this issue.
    : : :
    : : The Parent property is different from the Owner property and must be set separately (See above). The Owner property determines which object handle freeing the component (usually the form or datamodule), while the Parent handles repaints, TabOrder, and is only applicable to controls.
    : :
    : Thank you very much, that solves the problem. But there is just one more thing... is there any way of embedding this part in the constructor by converting owner to TWinControl? or do I need a new constructor with 2 parameters, of which one should be a control(the parent) and the other a component(the owner)?
    :
    : Thanks again
    : TataL_LoR
    :
    You can do both, if you like. Here's the code:
    [code]
    constructor TMyControl.Create(AOwner: TComponent); override;
    begin
    if AOwner is TWinControl then
    Create(AOwner, TWinControl(AOwner))
    else
    Create(AOwner, nil);
    end;

    constructor TMyControl.Create(AOwner: TComponent; AParent: TWinControl); virtual; reintroduce;
    begin
    inherited Create(AOwner);
    Parent := AParent;
    end;
    [/code]
Sign In or Register to comment.