Solved

Componet caption not refreshing properly

Posted on 2006-10-31
7
183 Views
Last Modified: 2010-04-05
Hi,

I need some helpw with this.  I have a new component (TCustomControl descendant).  The component has a Caption property declared as:

published
  property Caption;
..

end;

In the OnCreate method, I have the following code:

constructor TPAG_Label.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  TextCase := csUpperCase;
  AutoSize := false;
  Color := clWhite;
  BorderColor := clWhite;
  Alignment := taLeftJustify;
  Layout := tlTop;

  Caption := Name;
end;

In this instance, the caption of the component takes the name of the control (which is what I want).  However, if I now type some text into the caption property, or change the component name, the caption doesn't refresh at all.

Can someone give me some guidance please?

Thanks,

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
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17849165
Trying putting in these extra calls to update the label

constructor TPAG_Label.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  TextCase := csUpperCase;
  AutoSize := false;
  Color := clWhite;
  BorderColor := clWhite;
  Alignment := taLeftJustify;
  Layout := tlTop;

  Caption := Name;

  Refresh;
  Invalidate;
end;
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17849178
in fact Ive just noticed that this is the create of your label.
Where are you "typing some text"?

Your create will only set the caption of the label once, as this is all you have told it to do.
You need to then tell it to update the caption of the label once you have changed the text.
0
 

Author Comment

by:PAG_Promax
ID: 17855234
Its in the Object Inspector.  If I change the caption to "this is something new", it wont refresh until I move the control or resize it, or change one of the other properties which refreshes the control.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PAG_Promax
ID: 17943794
Any thing else that can be added to this at all?
0
 
LVL 4

Expert Comment

by:Meldrachaun
ID: 17963567
Try adding this method to your component:


procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;


procedure TMyComponent.CMTextChanged(var Message: TMessage);
begin
  Invalidate;
end;
0
 
LVL 4

Accepted Solution

by:
Meldrachaun earned 125 total points
ID: 17984249
Actually, it should probably be

procedure TMyComponent.CMTextChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;
0
 

Author Comment

by:PAG_Promax
ID: 18033259
Thanks for that!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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