Solved

Class type of Owner of component

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

628 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