?
Solved

How to change the color of the text at runtime

Posted on 2002-07-10
13
Medium Priority
?
353 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
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!

 

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

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!

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 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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 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