Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

TCustomPanel - Default Caption

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
MoonCalf
Asked:
MoonCalf
  • 6
  • 3
  • 2
  • +1
1 Solution
 
LRHGuyCommented:
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
 
Wim ten BrinkSelf-employed developerCommented:
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
 
MoonCalfAuthor Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
MoonCalfAuthor Commented:
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
 
MoonCalfAuthor Commented:
Incidentally, I've already made the caption property a published one in case it was due to it being protected.

MoonCalf.
0
 
MoonCalfAuthor Commented:
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
 
LRHGuyCommented:
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
 
LRHGuyCommented:
BTW, I do that in the create() method...
0
 
MoonCalfAuthor Commented:
Cheers LRHGuy - I'll give it a go.
0
 
MoonCalfAuthor Commented:
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
 
Wim ten BrinkSelf-employed developerCommented:
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
 
__alexCommented:
More about TComponent.Name:
http://www.marcocantu.com/papers/MyName.htm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now