这个函数,本来是能够实现,小数输入位数的,不知道哪里出了问题,限制不了小数输入位数,请帮我修改一下(100分)

  • 主题发起人 shankedriver
  • 开始时间
S

shankedriver

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure MxFormatKeyPress(Text:string;SelStart,SelLength:integer;
var Key:Char;EditType:integer;Digits:integer);
begin
if (Key=#27) or (Key=#8) or (EditType=1) then exit;
if EditType=2 then
if not (Key in ['0'..'9','+','-'] ) then Key:=#0;
if EditType=3 then
if not (Key in ['0'..'9','+','-','.'] ) then Key:=#0;
//控制+-
if (Key ='-') or (Key='+' ) then begin
if ((Pos('-',Text) > 0) or (Pos('+',Text) > 0 )) and
(SelLength=0 ) then Key:=#0;
if SelStart > 0 then Key:=#0;
end;
//控制.
if (Key = '.') and (EditType=3 ) then begin
if (Pos('.',Text) > 0) and (not((SelStart=Pos('.',Text) ))) then Key:=#0;
if SelStart=0 then Key:=#0;
if (Digits>0) and (SelStart+SelLength)>0 and (EditType=3) then
if (pos('.',Text )>0 ) and (SelStart>=pos('.',Text)) then
if length(Text)-pos('.',Text )>=Digits then Key:=#0;
end;
 
顶部