procedure TIntEdit.SetValue(Value: Integer);
begin
if FValue<>Value then
begin
FValue:=Value;
Text:=IntToStr(Value);
end;
end;
procedure TIntEdit.SetMaxValue (Value: Integer);
begin
if FMaxValue<>Value then
begin
FMaxValue:=Value;
if FValue>Value then SetValue(Value);
end;
end;
procedure TIntEdit.SetMinValue (Value: Integer);
begin
if FMinValue<>Value then
begin
FMinValue:=Value;
if FValue<Value then SetValue(Value);
end;
end;
//处理输入的字符
procedure TIntEdit.KeyPress(var Key: Char);
begin
if (Key=#13) and (Assigned(fEnterKey)) then fEnterKey(Self) //处理回车键
else if not ((Key In ['0'..'9']) or (Key=#8)) then //处理非数字字符
begin
Key:=#0;
if Assigned (fInputError) then fInputError(Self);
end;
end;
//当输入改变时判断输入是否合法
procedure TIntEdit.TextChange(Sender: TObject);
begin
if Text<>'' then
begin
fValue:=StrToInt(Text);
if fMaxValue<>0 then
if fValue>fMaxValue then
begin
Text:=FText;
fValue:=StrToInt(Text);
end
else FText:=Text;
end;
if (Text<>'') and ((Length(Text)=MaxLength) or ((StrToInt(Text)*10>MaxValue) and (fMaxValue>0)))
and Assigned(fMaxLength) then
fMaxLength(Self);
end;
procedure TIntEdit.LostFocus(Sender: TObject);
begin
if Text<>'' then
begin
FValue:=StrToInt(Text);
if Assigned(fLostFocus) then fLostFocus(Self);
end;
end;
begin
if not ((ord(Key)>=48) and (ord(Key)<=57) or (ord(Key)=8) or (ord(Key)=36) or (ord(Key)=35) or (ord(Key)=38) or (ord(Key)=40) or (ord(Key)=37) or (ord(Key)=39) or (ord(key)=46)) then
begin
showmessage('只可输入数值,不可输入其它字符!');
Key:=#0;
end;