Solved

TCustomPanel - Default Caption

Posted on 2004-10-11
12
428 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

24 Experts available now in Live!

Get 1:1 Help Now