var i:integer;
tmpStr:string;
begin
if key = VK_RETURN then
begin
tmpStr:=eschool.text;
if tmpStr='' then
beign
showmessage('请输入学校名称!');
exit;
end; //end of if tmpStr
for i:=1 to length(tmpStr) do
if ((tmpStr[i]>'0') and (tmpStr[i]<'9')) then
begin
showmessage('请输入汉字!')
jiguan.SetFocus;
exit;
end; //end of if & for
end;
tmpStr:string;
begin
if key = VK_RETURN then
begin
tmpStr:=eschool.text;
if tmpStr='' then
beign
showmessage('请输入学校名称!');
exit;
end; //end of if tmpStr
for i:=1 to length(tmpStr) do
if ((tmpStr[i]>'0') and (tmpStr[i]<'9')) then
begin
showmessage('请输入汉字!')
jiguan.SetFocus;
exit;
end; //end of if & for
end;
用var tmpStr:wideString; 更保险
你的方法不行,提示if ((tmpStr[i]>'0') and (tmpStr[i]<'9')) then
运行错误。
if (key not in ['0'..'9']) and (key<>#13) and (key<>#8)
and (key<>#0) then exit;
else
begin
try
strtofloat(eschool.Text); //如果转换成功,则说明是数字
ShowMessage('请输入汉字!');
eschool.SetFocus;
except
abort;
end;
end;
begin
if (key<='9') and (key>='0') then
begin
key:=#0;
showmessage('请输入汉字!');
exit;
end;
end;