Solved

TCustomPanel - Default Caption

Posted on 2004-10-11
12
430 Views
Last Modified: 2010-04-05
Hi.

I've created a component that is a descendant of TCustomPanel.  The problem I currently have with it is the fact that it has a caption (which I've never understood for TPanels anyway!), and the caption is the component's name.

I want to remove that or set it to '' when created.  I've added code (Caption:='') into the create event of the component, after the inherited call, and all the other code too, but it makes no difference.

Can someone advise me?

Ta,

Moonie.
0
Comment
Question by:MoonCalf
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12277126
I created a TCustomPanel myself, overriding nothing, and it came up blank....so I can only suggest you check for something else setting it.

type
  tcp=class(tCustomPanel)
  public
    constructor Create(aOwner:tComponent);
  end;


constructor tcp.Create(aOwner: tComponent);
begin
  inherited Create(aOwner);
  caption:=''; //force blank, in case it's not
end;
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12277163
Captions for panels are quite useful, actually. Since you can click on a panel, you can use a panel as a simplified button. You could also use the caption for a panel that is e.g. used for drag&drop purposes as a drop area. Captions are quite useful for panels...

The Caption property is defined in the TControl component thus every control has a caption. It's just that in many cases the caption stays protected. But the Caption property and the Text property are actually pointing to the same string value that is stored within the Window associated to the control. It's actually the Window text.
If you inherit it from TCustomPanel then the Caption property is probably still protected and would not show in the Delphi designer. Only TPanel itself is publishing it. So you could create your own published property instead.

If you change the Text property, it will change the Caption property too, though...
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12277174
Hi.

When you created it, did you give it a name?  A simple create is fine for what you've suggested but I'm naming the component when it's created in order to identify it later.

It's the name that shows in the caption.  I didn't have this problem until I started naming the components.  I did consider using a different property, such as "identity", instead of the name, but that's not really a solution to the problem - more a way round it.  I'd rather know how to handle this problem for when I face it in different arenas.

Thanks,

MoonCalf.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 1

Author Comment

by:MoonCalf
ID: 12277205
Hi Alex - thanks for the comments, but I don't see how that helps.  I did try setting the Text property to '' also, but to no avail.

Thanks,

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12277217
Incidentally, I've already made the caption property a published one in case it was due to it being protected.

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12277230
Actually, after a little more investigation, I've noticed that both the caption and the text properties do absolutely nothing to my component.

AGGHHH!!!!

Help?

Moonie.
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 100 total points
ID: 12277268
I looked at one of my older components to see how I did it...I set caption:=' '; (a space) and that keeps it from being reassigned to the component name when created by a component wizard.

0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12277292
BTW, I do that in the create() method...
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12277302
Cheers LRHGuy - I'll give it a go.
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 12277353
Nice - works perfectly.

There is one other wierdness about this component - it's not another question, but if anyone wants to offer anything it will be gratefully accepted!

It works fine now, for my purposes anyway.  I'm creating the components at runtime and assigning all the properties programmatically (each component relates to a file.)

Anyway, if I drop one on an empty form it does exactly what you'd expect.  The wierdness comes when I change the component name - name is not a published property in this case.  It's all fine until I leave the name field empty and press enter.  The component is visually still on the form, but not declared anywhere in the code.  (This obviously causes a runtime error when run, but the IDE's fine with it!)

Just thought it was strange so I'm sharing it : )

Thanks for all the help in the above problem.

MoonCalf.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12278582
The name property is used by the designer to add the component to your code. If you don't provide a name, it cannot generate a name in your code either. The component name has only one purpose: to provide a name to be used in your code. If you would create components dynamically, you can just skip providing a name.
It might or might not create a runtime error though. If you drop two TPanel components on your form and make the name of one of them empty then Delphi will just run fine. However, if you clear both names then your code doesn't know that you have a TPanel in your form. Even worse, it might not even realise what a TPanel is because it might not have a reference to the proper units. (Stripped away by the optimizer of Delphi.) Thus when it reads your form then it might not know what to do with a TPanel, thus crash.
However, if you use at least one TPanel in your code with a name, the optimizer will NOT strip away the class, thus Delphi is able to read it.

It is just fine to have components without a name on your form. It's just that you have to make sure the optimizer doesn't strip them away from your code so your code must have at least one reference to their classes. (And it gets a bit more complicated too from here onwards.)
0
 
LVL 2

Expert Comment

by:__alex
ID: 12284303
More about TComponent.Name:
http://www.marcocantu.com/papers/MyName.htm
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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