Link to home
Start Free TrialLog in
Avatar of siki
sikiFlag for Serbia

asked on

How to change DBEdit read-only color?

I have form with DBEdits. Some of them (or all) became read-only at runtime. How to change DBEdit color
(in read-only state at runtime) to color different than white nad back to normal when it's not read-only?
Changes occurs on Dataset state change.
Avatar of CrazyOne
CrazyOne
Flag of United States of America image

Here is example I but in side a button so you can get an idea of how to change it base on the ReadOnly property.

procedure TForm1.Button1Click(Sender: TObject);
begin

  with DBEdit1 do begin
     ReadOnly := not ReadOnly;    
     If ReadOnly then begin
            Color := clBtnFace;
            Font.Color := clBtnText;
      end
       else begin
             Color := clWindow;
             Font.Color := clWindowText;
       end;

  end;  

end;
Avatar of Pandian012000
Pandian012000

Hi

In your form show event try this

  if ded_alotdate.ReadOnly = true then
  begin
    ded_alotdate.Color := clred;
  end else
  begin
    ded_alotdate.Color := clwindow;
  end;


Regards
Pandian
Avatar of Mohammed Nasman
Hi Pandian
   sinisanenkov said:
>Changes occurs on Dataset state change.

 but what you post as answer will check first time when form show, and if the state changed again it will not change the color :)
Yeah that was my understanding that the readonly would change at various times troughout the apps life.

Here is the same example from before but with some changes,

procedure TForm1.Button1Click(Sender: TObject);
begin

     DBEdit1.ReadOnly := not DBEdit1.ReadOnly;    
      SetDBEditColor(DBEdit1);    
 
end;

procedure TForm1.SetDBEditColor(Sender: TDBEdit);
begin

     If Sender.ReadOnly then begin
          Sender.Color := clBtnFace;
          Sender.Font.Color := clBtnText;
     end
     else begin
          Sender.Color := clWindow;
          Sender.Font.Color := clWindowText;
       end;

end;
Yeah that was my understanding that the readonly would change at various times troughout the apps life.

Here is the same example from before but with some changes,

procedure TForm1.Button1Click(Sender: TObject);
begin

     DBEdit1.ReadOnly := not DBEdit1.ReadOnly;    
      SetDBEditColor(DBEdit1);    
 
end;

procedure TForm1.SetDBEditColor(Sender: TDBEdit);
begin

     If Sender.ReadOnly then begin
          Sender.Color := clBtnFace;
          Sender.Font.Color := clBtnText;
     end
     else begin
          Sender.Color := clWindow;
          Sender.Font.Color := clWindowText;
       end;

end;
Sorry for the double post my finger flitched, really it did. :>)
ASKER CERTIFIED SOLUTION
Avatar of VSF
VSF
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of siki

ASKER

NO, PANDIAN! Your solution dosn't working. VSF posted good comment. It's about DBEdits, not simple TEdits. I am littke bit souprised, how hard is to change simple disabled edit color. I think, VB have done this in properties of comp.
Avatar of siki

ASKER

NO, PANDIAN! Your solution dosn't working. VSF posted good comment. It's about DBEdits, not simple TEdits. I am littke bit souprised, how hard is to change simple disabled edit color. I think, VB have done this in properties of comp.
Avatar of siki

ASKER

NO, PANDIAN! Your solution dosn't working. VSF posted good comment. It's about DBEdits, not simple TEdits. I am littke bit souprised, how hard is to change simple disabled edit color. I think, VB have done this in properties of comp.
Avatar of siki

ASKER

NO, PANDIAN! Your solution dosn't working. VSF posted good comment. It's about DBEdits, not simple TEdits. I am littke bit souprised, how hard is to change simple disabled edit color. I think, VB have done this in properties of comp.
I'm glad I could help!

and thanks for the points.


VSF
www.enge.cjb.net
www.victory.hpg.com.br
UIN:14016999