在输入框的ONKeyPress函数中判断
Txm := trim(AEdit.Text);
if pos('.',Txm)>0 then
begin
if (key in ['0','1','2','3','4','5','6','7','8','9']) or (key=#13) or (key=#8) then
key := key
else
key := #0;
end
else
begin
if (key in ['0','1','2','3','4','5','6','7','8','9','.']) or (key=#13) or (key=#8) then
key := key
else
key := #0;
end;
至于输入的字符最后保留什么格式的话,你可以在OnExit函数中自己处理
写了一个检查是否有多个点的函数:
function Isdot(const dot: string): Boolean;
var
i, lenstr, zd: integer;
begin
Result := False;
zd := 0;
lenstr := Length(trim(dot));
for i := 1 to lenstr - 1 do
begin
if pos('.', copy(trim(dot), i, 1)) > 0 then
begin
zd := zd + 1
end;
if zd > 1 then
begin
Result := true;
end
else
begin
Result := False;
end;
end;
end;