TDBEdit颜色设置问题(50分)

  • 主题发起人 主题发起人 端木飘零
  • 开始时间 开始时间

端木飘零

Unregistered / Unconfirmed
GUEST, unregistred user!
我的窗体里有很多TDBEdit,我想在每个TDBEdit的OnExit中判断TDBEdit的值,如果值不为空,则颜色为红色,如果为空,则颜色为灰色,怎么实现?
procedure Tfrm_yw_szfx1.Button1Click(Sender: TObject);
var i:integer;
begin
with ScrollBox1do
for i:=0 to ControlCount-1do

begin
if (Controls is TDBEdit) then

with Controls as TDBEditdo
begin
if text='' then
begin
Font.Color:=clGray;
end
else
begin
Font.Color:=clBlue;
end;
end;
end;
end;

上面这段代码属于遍历所有控件,有点浪费,如何将这段代码修改,让他作为每个Tdbedit的onexit事件触发事件?
 
onexit中:
(Sender as TDBEdit ).font.color:=clGray;
 
OnExit事件:
with TDBEdit(Sender)do
begin
if text='' then
begin
Font.Color:=clGray;
end
else
begin
Font.Color:=clBlue;
end;
end;
 
哈哈,自力更生,搞定,解决方法如下:
procedure Tfrm_yw_szfx1.SetControlProc();
var i:integer;
begin
with ScrollBox1do
for i:=9 to ControlCount-10do
//±éÀú´°ÌåËùÓпؼþ
begin
if (Controls is TDBEdit) then
begin
TDBEdit(Controls).OnExit:=ControlOnExit;
TDBEdit(Controls).OnEnter:=ControlOnEnter;
end;
end;
end;

procedure Tfrm_yw_szfx1.ControlOnExit(Sender:TObject);
begin
with TDBEdit(sender)do
begin
color:=clWhite;
if strtofloat(text)>0 then
begin
Font.Color:=clActiveCaption;
Font.Style:=[fsBold];
end
else
begin
Font.Color:=clGray;
Font.Style:=[];
end;
end;
end;

procedure Tfrm_yw_szfx1.ControlOnEnter(Sender:TObject);
begin
with TDBEdit(sender)do
begin
//color:=clActiveCaption;
Font.Color:=clRed;
Font.Style:=[fsBold];
SelectAll;
end;
TDBEdit(sender).SelectAll;
end;
 
procedure Tfrm_yw_szfx1.DBEdit1Change(Sender: TObject);
begin
if TDBEdit(Sender).Text = '' then
TDBEdit(Sender).Color:=clGray
else
TDBEdit(Sender).Color:=clBlue;
end
procedure Tfrm_yw_szfx1.Button1Click(Sender: TObject);
var i:integer;
begin
with ScrollBox1do
for i:=0 to ControlCount-1do

begin
if (Controls is TDBEdit) then

with Controls as TDBEditdo
TDBEdit(Controls).OnChange := DBEdit1Change;
end;
end;
 
解决了问题怎么分没给啊?
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部