Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"control '' has no parent"  error...

Posted on 2001-08-07
4
Medium Priority
?
263 Views
Last Modified: 2010-04-04
Hi,
  I'm writing a visual component based on TPaintBox.
but the create method raise the error :"control '' has no parent", I don't understant why. Can you help me ?

  I reduced the code to the max in order to keep the error :

unit PaintBox1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TPaintBox1 = class(TPaintBox)
  private
  protected
  public
    constructor create(AOwner:Tcomponent);Override;
  published
  end;

procedure Register;
implementation

constructor TPaintBox1.Create(AOwner:Tcomponent);
var R:TRect;
begin
  inherited;
  R.Top:=5;
  R.Left:=5;
  R.Bottom:=Height-5;
  R.Right:=width-5;
  Self.Canvas.Brush.color:=clLime;
  Self.Canvas.FillRect(R);
end;

procedure Register;
begin
  RegisterComponents('Additional', [TPaintBox1]);
end;

end.

Thanks for help.

Mike
0
Comment
Question by:gklux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6358750
Try
  inherited Create(AOwner);
0
 

Author Comment

by:gklux
ID: 6358760
Sorry, the full error message is :
"control '' has no parent window"

Mike
0
 
LVL 20

Accepted Solution

by:
Madshi earned 400 total points
ID: 6358821
constructor TPaintBox1.Create(AOwner:Tcomponent);
var R:TRect;
begin
 inherited;
 R.Top:=5;
 R.Left:=5;
 R.Bottom:=Height-5;
 R.Right:=width-5;

This is alright. But this...

 Self.Canvas.Brush.color:=clLime;
 Self.Canvas.FillRect(R);

... fails, because in the moment where you access the Canvas property, a handle to the paintbox is needed. But a handle can only be created if the parent window of the paint box is known. But the parent is known later, not in the constructor.
So I recommend to move the canvas stuff to a "later location". Maybe you can overwrite the "SetParent" method and do it there, after the parent was set to a non-nil value.

Regards, Madshi.
0
 

Author Comment

by:gklux
ID: 6359270
Very helpfull answer Madshi, has always  :-)

regards

Mike
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question