Solved

Class type of Owner of component

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 203
Delphi application Soap connection 5 132
how can i search if string exist in array ? 3 69
Using MMsystem To change audio input 1 17
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

749 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