spinedit可否設置成可直接輸入小數(5分)

  • 主题发起人 fluganto
  • 开始时间
F

fluganto

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
[:(]各位大哥,請教一下在spinedit中能否設成可直接輸入小數,並控制可輸入
小數的位數,或者有無其他控件能實現這個功能,萬分感謝!!
 
spinedit中不能輸入小數,
 
procedure TSpinEdit.SetValue (NewValue: LongInt);
begin
Text := IntToStr (CheckValue (NewValue));
end;

function TSpinEdit.GetValue: LongInt;
begin
try
Result := StrToInt (Text);
except
Result := FMinValue;
end;
end;

function TSpinEdit.CheckValue (NewValue: LongInt): LongInt;
begin
Result := NewValue;
if (FMaxValue <> FMinValue) then
begin
if NewValue < FMinValue then
Result := FMinValue
else if NewValue > FMaxValue then
Result := FMaxValue;
end;
end;

重载以上方法,修改Spin.pas加入下面的代码

procedure TSpinEdit.SetValue (NewValue: double);overload;
begin
Text := flaotToStr (CheckValue (NewValue));
end;

function TSpinEdit.GetValue: double;overload;
begin
try
Result := StrToflaot (Text);
except
Result := FMinValue;
end;
end;

function TSpinEdit.CheckValue (NewValue: double): double;overload;
begin
Result := NewValue;
if (FMaxValue <> FMinValue) then
begin
if NewValue < FMinValue then
Result := FMinValue
else if NewValue > FMaxValue then
Result := FMaxValue;
end;
end;

 
謝謝各位的回答,不知道Delphi中有沒有可以控制直接小數的控件?
 
TMaskEdit设置相应的属性
 
Tmaskedit好象不太好,我設定可以輸入5位整數,3位小數的話,我隻輸入3位整數,1位小數
就不可以,不知道是不是還有什麼屬性沒設好?
 
OnExit 中删除中间的空格,
并进行转换:
try
//删除中间空格
x:=strtofloat(madkedit.text)
except
maskedit.setfocus;
end;
 
多人接受答案了。
 
顶部