// 返回某个字符串中某个字符串中出现的次数}
function TForm1.StrNum(ShortStr:string;LongString:string):Integer;
var
i:Integer;
begin
i:=0;
while pos(ShortStr,LongString)>0 do
begin
i:=i+1;
LongString:=copy(LongString,(pos(ShortStr,LongString))+1,Length(LongString)-pos(ShortStr,LongString))
end;
Result:=i;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if length(Edit1.Text)=0 then
begin
if not (Key in['0'..'9','-','.',#27{ESC},#8{退格},#13{回车}]) then
begin
key:=#0;
end;
if StrNum('.',Edit1.Text)>0 then
begin
if not (Key in['0'..'9',#27{ESC},#8{退格},#13{回车}]) then
begin
key:=#0;
end;
end;
end
else
begin
if not (Key in['0'..'9','.',#27{ESC},#8{退格},#13{回车}]) then
begin
key:=#0;
end;
if StrNum('.',Edit1.Text)>0 then
begin
if not (Key in['0'..'9',#27{ESC},#8{退格},#13{回车}]) then
begin
key:=#0;
end;
end;
end;
end;