[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to change the color of the text at runtime

Posted on 2002-07-10
13
Medium Priority
?
356 Views
Last Modified: 2010-04-04
I have written common function to make the components
readonly at runtime. Now i also want to change the color of the components.

My code is like this

PRecProp := GetPropInfo(Components  
                        [intI].ClassInfo, 'ReadOnly');
if Assigned(PRecProp) then begin
   SetOrdProp(Components[intI], PRecProp, Integer(not
                                      (blnValue)));
 

How can i do that?

Rajni:)
0
Comment
Question by:rajniyadav
[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
13 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 7145691
Hi,

PRecProp := GetPropInfo(Components  
                       [intI].ClassInfo, 'Color');
if Assigned(PRecProp) then begin
  SetOrdProp(Components[intI], PRecProp, clRed);

Regards, Geo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7146198
instead of to make it readonly, just set the enabled-propery to false,
the textcolor depending on the control is then normally grayed automatically

meikl ;-)
0
 

Author Comment

by:rajniyadav
ID: 7148224
geobul

I cannot user color property because that will change the background color of the components. I want to change the text color of the component i.e Font.Color

kretzschmar

I cannot enable or disable control because if the text in it is more than the length of the component then i cannot move forward to see the remaining text.

rajni

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!

 

Expert Comment

by:BaSoAM
ID: 7148253
If you're just changing the color of the text and not making them read-only then you can still use the Show Hint property of the editbox.  

edit1.showhint := true;
edit1.hint := edit1.text;

this way you won't need to scroll to see the whole thing and is a better interface.  You can just move mouse over the editbox and without additional steps you can read the entire input.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7148511
Hi,

PRecProp := GetPropInfo(Components[intI].Font.ClassInfo, 'Color');
if Assigned(PRecProp) then begin
 SetOrdProp(Components[intI].Font, PRecProp, clGray);

Regards, Geo
0
 

Author Comment

by:rajniyadav
ID: 7148608
geobul

I tried your code but it give error for Component[inti].Font. It says undeclared identifier.


Rajni
0
 
LVL 10

Expert Comment

by:kacor
ID: 7148943
Hi Rajni,

you typed it wrong. You have to write INTL instead of INTI

regards

Janos
0
 

Author Comment

by:rajniyadav
ID: 7148979
Janos

I am using intI variable in my code instead of intL so that's not the case

Rajni

0
 
LVL 17

Expert Comment

by:geobul
ID: 7149032
Well, I supposed that you had some type checking before that code like if .. is TEdit then ..

Font property is introduced in TControl, so:

if (Components[intI] is TControl) then begin
  PRecProp := GetPropInfo((Components[intI] as TControl).Font.ClassInfo, 'Color');
  if Assigned(PRecProp) then SetOrdProp((Components[intI] as TControl).Font, PRecProp, clGray);
end;

Regards, Geo
0
 

Author Comment

by:rajniyadav
ID: 7153581
geobul

I am writing this but still it gives me the same error
Undeclared identifier 'Font'
 
if (Components[intI] is TControl) then begin
  PRecProp := GetPropInfo((Components[intI] as  
                    TControl).Font.ClassInfo, 'Color');
  if Assigned(PRecProp) then begin
    SetOrdProp((Components[intI] as
             TControl).Font, PRecProp, clGray);
  end;
end;


Rajni
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 7153672
I'm sorry, my mistake. TControl.Font property is a protected one and therefore not visible. So the solution is:

  // define a new class used for typecasting only
  THackControl = class(TControl)
  public
    property Font;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses TypInfo;

function SetFontColor(fForm: TForm; sControl: string; value: integer): integer;
var
  i: integer;
  PRecProp: PPropInfo;
begin
 result := 0;
 try
  for i := 0 to fForm.ComponentCount - 1 do
    if (fForm.Components[i] is TControl) then
      if (fForm.Components[i]).Name = sControl then begin
        PRecProp := GetPropInfo(THackControl(fForm.Components[i]).Font.ClassInfo, 'Color');
        if Assigned(PRecProp) then
           SetOrdProp(THackControl(fForm.Components[i]).Font, PRecProp, value);
        break;
      end;
 except
   result := 1;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetFontColor(Form1,'Label1', clRed);
  SetFontColor(Form1,'Edit1', clRed);
end;

Regards, Geo
0
 

Author Comment

by:rajniyadav
ID: 7168728
geobul

your solution works thanx a lot

Rajni
0
 
LVL 17

Expert Comment

by:geobul
ID: 7169143
The pleasure was mine :-)
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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