在系统中有些文本框要输入金钱的框中,MaskEdit没有最好办法让它自动计算
现在我想做一个继承组件只能输入数字和小数点
我的程序如下但还有一个问题就是怎样去判断小数点是否被删除????
unit CheckEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TCheckEdit = class(TEdit)
private
FFlagCount:integer;
protected
procedure KeyPress(var Key: Char); override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.KeyPress(var Key: Char);
begin
inherited;
if (Key = '.') and (FFlagCount<1) then Inc(FFlagCount)
else If (Key>='9') or (Key<='0') then Key := #0;
end;
end.
现在我想做一个继承组件只能输入数字和小数点
我的程序如下但还有一个问题就是怎样去判断小数点是否被删除????
unit CheckEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TCheckEdit = class(TEdit)
private
FFlagCount:integer;
protected
procedure KeyPress(var Key: Char); override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.KeyPress(var Key: Char);
begin
inherited;
if (Key = '.') and (FFlagCount<1) then Inc(FFlagCount)
else If (Key>='9') or (Key<='0') then Key := #0;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
index : integer;
begin
s := edit1.Text;
index := Pos ('.',s);
if index <> 0 then
Delete (s,index,1);
edit1.Text := s;
end;
过程谁都知道写再问就没意思了
sunkyling(尉迟冉冉) ‘自己写个组件就ok 了’我上面是组件呀又怎么加入我要的功能呢??各位回复者,看清问题再回吧要不我很难看的。
如你有好方式可以提出但必须为组件方式。首先向一个与问题无关的回复者说一声‘对不起’,你的回复我可能会删除的
if pos('.',TEdit(sender).Text)<=0 then showmessage('小数点已被删除!');