该控件是在procedure Change(); override; 事件里写的控制颜色代码。 把控件装上delphi后,在实际应用中却遇到这个问题
解决方案 »
- 怎么重新显示或者调用主窗体,以及他们之间的关系
- STRINGGRID 与DBGRIDEH 冲突问题
- isapi+dbisam iis 运行报错 求高人指点
- 为什么MDI子窗体一显示,系统就用MDI的子窗体菜单取代了MDI的主菜单?我怎么在保留MDI主窗口菜单的情况下,往主菜单里面添加我的子窗体菜
- 請教﹕怎樣把ListView的值加載到數據庫。急急100分贈送
- 有谁作过任务管理.到底有那些需求
- 如何得到dbgrid的当前选中行的某一字段的值呢?
- 请问,把一张表的记录(多个字段值)select出来过后,现把这个记录保存起来,用以保存这个记录的变量该怎样来定义呢?delphi中有没有象c
- 套接字出错如何解决??
- 兄弟们,救救我吧,我非得吧硬盘里得程序给弄出来!
- 如何在单机下测试自己做的client和sever?
- 声卡的问题?
procedure TForm1.DBEdit1Change(Sender: TObject);
begin
if (DBEdit1.Field.AsFloat>100) then
DBEdit1.Font.Color := clRed
else if (DBEdit1.Field.AsFloat>200) then
DBEdti1.Font.Color := clBlue
else if ...
end;
procedure TForm1.DBEdit1Change(Sender: TObject);
begin
if Length(DBEdit1.Text) > 5 then DBEdit1.Font.Color := clRed
else DBEdit1.Font.Color := clBlue
end;
让用户输入数值, 当控件的text值变化时,和Maxvalues,Minvalues比较,并用不同的颜色表示, 当然,还要象TDBEdit一样能保存数据!
控件的源程序如下:unit WarnDBEdit;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ADODB,
StdCtrls, Mask, DBCtrls;type
TWarnDBEdit = class(TDBEdit)
private
{ Private declarations }
FMYTableName: string;
FMYDataset: TADODataset; //数据集
FMYConnection: TADOConnection;
protected
{ Protected declarations }
constructor create(AOwer: TComponent);override;
procedure Change(); override;
public
{ Public declarations }
published
{ Published declarations }
//TableName是指与其datasource指向的表是同一个表
property TableName: string read FMYTableName write FMYTableName;
property Connection: TADOConnection read FMYConnection write FMYConnection; end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TWarnDBEdit]);
end;constructor TWarnDBEdit.create(AOwer: TComponent);
begin
inherited;
end;procedure TWarnDBEdit.Change();
var
strsql:string;
values:real;
begin
self.Font.Color:=clWindowText;if trim(self.TableName)<>'' then
begin
strsql:='select max,min from syxm where upper(tablename)='''+UpperCase(self.TableName)+''''+
' and upper(fieldname)='''+uppercase(self.datafield)+'''';
FMYDataset:=TADODataset.Create(self);
FMYDataset.Connection:=FMYConnection;
FMYDataset.LockType:=ltReadOnly;//将数据集设为只读
FMYDataset.CommandText:=strsql;
FMYDataset.Open;
if self.text='' then
values:=0
else
values:=strtofloat(self.text);
if values > FMYDataset.fieldbyname('max').AsFloat then
self.Font.Color:= clRed; if values = FMYDataset.fieldbyname('max').AsFloat then
self.Font.Color:= clMaroon; if values < FMYDataset.fieldbyname('min').AsFloat then
self.Font.Color:= clBlue; if values = FMYDataset.fieldbyname('min').AsFloat then
self.Font.Color:= clNavy;
FMYDataset.Close;
FMYDataset.Free;
end;
end;end.
发现那个问题后,后来为了测试方便,就改成在控件里提供两个属性Maxvalues,Minvalues
让用户输入数值, 当控件的text值变化时,和Maxvalues,Minvalues比较,并用不同的颜色表示,但做出来后控件却放不上Form,提示该控件 is not a valid floating point values,unit WarnDBEdit2;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ADODB,
StdCtrls, Mask, DBCtrls;type
TWarnDBE = class(TDBEdit)
private
{ Private declarations }
FMYMax:real;
FMYMin:real;
protected
{ Protected declarations }
constructor create(AOwer: TComponent);override;
procedure Change(); override;
public
{ Public declarations }
published
{ Published declarations }
property MaxValues: real read FMYMax write FMYMax ;
property MinValues: real read FMYMin write FMYMin ;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TWarnDBE]);
end;constructor TWarnDBE.create(AOwer: TComponent);
begin
inherited;
end;procedure TWarnDBE.Change();
var
values,max,min:real;
begin
self.Font.Color:=clWindowText; if self.text='' then
values:=0
else
values:=strtofloat(self.text); max:=self.MaxValues;
min:=self.MinValues; if values > Max then
self.Font.Color:= clRed; if values = Max then
self.Font.Color:= clMaroon; if values < Min then
self.Font.Color:= clBlue; if values = Min then
self.Font.Color:= clNavy;
end;
end.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ADODB,
StdCtrls, Mask, DBCtrls;type
TWarnDBE = class(TDBEdit)
private
{ Private declarations }
FMYMax:real;
FMYMin:real;
protected
{ Protected declarations }
constructor create(AOwer: TComponent);override;
procedure Change(); override;
public
{ Public declarations }
published
{ Published declarations }
property MaxValues: real read FMYMax write FMYMax ;
property MinValues: real read FMYMin write FMYMin ;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TWarnDBE]);
end;constructor TWarnDBE.create(AOwer: TComponent);
begin
inherited;
end;procedure TWarnDBE.Change();
var
values,max,min:real;
begin
self.Font.Color:=clWindowText;
try
if self.text='' then
values:=0
else
values:=strtofloat(self.text); max:=self.MaxValues;
min:=self.MinValues; if values > Max then
self.Font.Color:= clRed; if values = Max then
self.Font.Color:= clMaroon; if values < Min then
self.Font.Color:= clBlue; if values = Min then
self.Font.Color:= clNavy;
except
end;
end;end.