Solved

Class type of Owner of component

Posted on 2006-11-01
5
280 Views
Last Modified: 2013-11-23
Hi all,

How do I tell what the owner class type is for my component?  I'm doing this:

constructor TPAG_FormCaptionBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ShowMessage(AOwner.ClassName);
end;

And it is ALWAYS showing me TForm1 - not TForm.   And when I drop the component onto a TPanel, it's still saying TForm1.

Isn't the owner of the new component the container I dropped it into?  

Thanks very much.

Pag
0
Comment
Question by:PAG_Promax
5 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 63 total points
ID: 17856136
>>And it is ALWAYS showing me TForm1 - not TForm.   And when I drop the component onto a TPanel, it's still saying TForm1.

This is because your current form is derived from TForm. and your form is the owner of the component you dropped not the Tform.

>>Isn't the owner of the new component the container I dropped it into?  
The container is a parent of the component you dropped. The owner will be the form.

I would suggest to read on Ownership and Parent relationships.
0
 
LVL 28

Assisted Solution

by:TName
TName earned 62 total points
ID: 17857025
>I would suggest to read on Ownership and Parent relationships.
The best possible suggestion.

For instance:
http://delphi.about.com/od/objectpascalide/l/aa031301a.htm

>And it is ALWAYS showing me TForm1 - not TForm.
Yes, and this is why:
var
  Form1: TForm1;  
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 17858168
ShowMessage('Class Name '+Panel1.Parent.ClassName);

If Panel1 is placed on say a Groupbox, it will say Groupbox.
0
 

Author Comment

by:PAG_Promax
ID: 17862760
Hi folks,

Thanks for the replies.  I'll definately read that link you sent, TName.  Special thanks to atul_parmar for the good explanation.

Maybe I should explain what I'm trying to do.  I'm writing a control which I only want to have dropped on a form.  If it's put on anything else, it will raise an exception and free itself.  What I am trying to do is check that the parent is a TForm and not something like a TPanel.

Sorry, I should have said that in the first place.

I'll have a read through the website now, and read a bit more in my books.  

Thanks again,

Pag.
0
 

Author Comment

by:PAG_Promax
ID: 17862834
Now I understand the Parent/Owner basics, I have changed my control so no matter what I drop the control onto, it always parents to the form.  So I dont need to raise an exception or anything, because it's always going to be right.

Thanks very much for your help.  I'll split the points on this one between TName and atuk_parmar.

Cheers!

Pag
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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