Solved

Componet caption not refreshing properly

Posted on 2006-10-31
7
174 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Expert Comment

by:Meldrachaun
Comment Utility
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
Comment Utility
Actually, it should probably be

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

Author Comment

by:PAG_Promax
Comment Utility
Thanks for that!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

18 Experts available now in Live!

Get 1:1 Help Now