Solved

Componet caption not refreshing properly

Posted on 2006-10-31
7
182 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
  • 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
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

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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