那位老大帮我实现这些功能啊
继承TDBEdit写控件实现以下功能
比如设定了4位小数1、连接数据后多余4位小数的就四舍五入,不够4位的就在后边添零 例如数据库是2.1的话 读出来就是2.1000 如果是2.12345的话读出来就是2.12352、得到焦点的时候,如果在得到焦点的时候是2.1000就变为2.13、失去焦点的时候,失去前是2.1的话就变为2.1000,如果是2.12345的话就变为2.1235没什么分,大虾们帮下忙啊。。
继承TDBEdit写控件实现以下功能
比如设定了4位小数1、连接数据后多余4位小数的就四舍五入,不够4位的就在后边添零 例如数据库是2.1的话 读出来就是2.1000 如果是2.12345的话读出来就是2.12352、得到焦点的时候,如果在得到焦点的时候是2.1000就变为2.13、失去焦点的时候,失去前是2.1的话就变为2.1000,如果是2.12345的话就变为2.1235没什么分,大虾们帮下忙啊。。
解决方案 »
- 在onresize里面写form1.postion:=poScreenCenter;报错?
- cxGrid1DBBandedTableView1.DataController.SetValue 的问题
- 急请教!Out Look 时间预定报
- errorcode:=0;是什么意思呀,
- DBGrid1又一个问题??
- 请问毛玻璃效果怎么实现?
- 在WebBrowser1的NewWindow2事件中,如何知道要打开的url
- DateTimePicker1怎样得到多少年,多少月
- 100分求购软件远程升级方案!(比如说像美萍一样)
- 使用batchmove控件的问题:
- 怎么让pascal写的cgi程序写文件?
- 请问你的 AdvMDIOfficeTabSet 控件是怎样用的?? 可以给我一个例子?
SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls;
type
TNumType = (None, Amount, Numerical);type
TDBNumEdit = class(TDBEdit)
private
FNumType: TNumType;
iDecPlaces: integer;
bCanNegative, bHaseChanged: boolean;
sTemText: string;
procedure KeyPress(var Key: Char); override;
procedure CMExit(var AMsg: TCMExit); message CM_EXIT;
procedure CMEnter(var AMsg: TCMEnter); message CM_ENTER;
procedure Change; override;
protected public
HaseChanged: boolean;
constructor Create(AOwner: TComponent); override;
published
property NumType: TNumType read FNumType write FNumType default None;
property DecPlaces: integer read iDecPlaces write iDecPlaces default 0;
property CanNegative: boolean read bCanNegative write bCanNegative default False;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Data Controls', [TDBNumEdit]);
end;{ TDBNumEdit }procedure TDBNumEdit.Change;
begin
inherited Changed; if not Focused then
if (Trim(Text) <> '') and (Trim(Text) <> '-') then
Text := formatfloat('0' + copy('.000000000', 1, DecPlaces + 1), strtofloat(Text));
end;procedure TDBNumEdit.CMEnter(var AMsg: TCMEnter);
begin
if (Trim(Text) <> '') and (Trim(Text) <> '-') then
Text := formatfloat('0.#########', strtofloat(Text));
sTemText := Trim(Text);
end;procedure TDBNumEdit.CMExit(var AMsg: TCMExit);
begin
if sTemText <> Trim(Text) then
HaseChanged := True
else
HaseChanged := False;
if (Trim(Text) <> '') and (Trim(Text) <> '-') then
Text := formatfloat('0' + copy('.000000000', 1, DecPlaces + 1), strtofloat(Text));
end;constructor TDBNumEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner); Text := '0.00';
end;procedure TDBNumEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key); if not (Key in['0'..'9', '.', '-', #8, #13]) then
begin
Key := #0;
end
else if Key = '.' then
begin
if Pos('.', Text) <> 0 then
Key := #0;
end
else if (Key = '-') then
begin
if not CanNegative then
Key := #0
else if text <> '' then
begin
if (Pos('-',Text) > 0) and (SelLength=0) then
Key := #0;
if SelStart > 0 then Key:=#0;
end;
end;
end;end.自己写了一个,但有两个问题:
1、控件获得焦点后有时候内容不不能自动靠左。
2、控件放到窗体上的时候有数据转换问题。
望哪位高手解决下,谢谢