从一个第3方控件里找到一个检查是否数字的方法,你放在数值输入前判断,如果是数字则输入,不是则不允许输入
TValueType = (vtInteger, vtFloat);
ValueType:TValueType;
function IsNumText(AText: String): Boolean;
function GetMinus: Boolean;
var
i: Integer;
S: String;
begin
S := AText;
i := Pos('-', S);
if i > 1 then
Result := False
else
begin
Delete(S, i, 1);
Result := Pos('-', S) = 0;
end;
end;
function GetP: Boolean;
var
i: Integer;
S: String;
begin
S := AText;
i := Pos(DecimalSeparator, S);
if i = 1 then
Result := False
else
begin
Delete(S, i, 1);
Result := Pos(DecimalSeparator, S) = 0;
end;
end;
const
EditChars = '01234567890-';
var
i: Integer;
S: String;
begin
S := EditChars;
Result := True;
if ValueType = vtFloat then
S := S + DecimalSeparator;
if (AText = '') or (AText = '-') then
begin
Result := False;
Exit;
end;
for i := 1 to Length(AText) do
begin
if Pos(AText, S) = 0 then
begin
Result := False;
Break;
end;
end;
Result := Result and GetMinus;
if ValueType = vtFloat then
Result := Result and GetP;
end;