Solved

Class type of Owner of component

Posted on 2006-11-01
5
277 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
Comment Utility
>>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
Comment Utility
>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
Comment Utility
ShowMessage('Class Name '+Panel1.Parent.ClassName);

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

Author Comment

by:PAG_Promax
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now