Solved

Class type of Owner of component

Posted on 2006-11-01
5
285 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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