使用StrToInt
同时抓异常.
同时抓异常.
解决方案 »
- 如何在窗体加载过程中屏蔽NumericUpDown1.ValueChanged事件
- cxGrid怎么添加一条新的空记录啊
- HitTests怎莫用
- 如何动态把一个控件放入一个容器问题!(论坛维护所无发搜索)
- 年纪不小了,还在考虑生计问题,烦,放分
- windows98下怎么设置环境变量path的值?大侠们帮忙
- 怎樣讓窗體打開的時候是最大化的
- 各位中国人,注意了!!!必看!!!!
- 猜中比分者给30分
- 在winow2000数据库不读取数据,但在win98却可以不知什么原因?
- 看过我贴子(http://www.csdn.net/expert/topic/958/958167.xml?temp=.1907923)的朋友来这里领分(2),实现我的承诺,每人20
- 请问TwwDbGrid是什么名称的控件包安装的呀?
strtoint(youstring);
except
end;
用try如果没有触发异常的话就可以有的话就说明不是要不就自己写一个这样的函数吧。。写完了最好可以在这里发布一下。应该不难的。。
try
strtoint(string);
isint:=true; //isint是布尔型变量;
except
isint=:false;
end;
//判断结果
if isint=true then
showmessage('字符串是数字')
else
showmessage('字符串不是数字');
用
procedure Val(S; var V; var Code: Integer)Converts a string to a numeric representation.uses Dialogs;
var I, Code: Integer;
begin
{ Get text from TEdit control }
Val(Edit1.Text, I, Code);
{ Error during conversion to integer? }
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0);
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));end;
strtoint(youstring);
except
end;
這個應該沒有問題;不過若是小數可就不行,我給你一個functionfunction CheckNumber(sTmp: string): boolean;
// 判斷字符串str1是否數字型字符串(包含小數點'.'),
// 返回邏輯結果True,False
var
i, j : integer;
begin
checknumber := True;
J := 0;
for i := 1 to length(sTmp) do
begin
case sTmp[i] of
'0'..'9':;
'.': inc(J);
else checknumber := False;
end;
end;
if J>1 then checknumber := False;
end;
if StrToIntDef(astr,-1) <> -1 then 是字符串
StrToIntDef 把字符串转换成整形,如果失败,返回第二个参数的值,在这里是-1