delphi 中怎样检测edit.text是不是空呢?还有个问题,在里面

来源:百度知道 编辑:UC知道 时间:2024/07/02 12:37:01
我的代码在下面,我要创建个计算平方窗口,一直显示
if edit1.Text :='' then错误,我就只好添加了个c1,再和edit1.text相等,检测Boolean型。
这里显示有链各个错,一个是上面一句,一个是a2:= strtoint64(a1)这句,想先把字符串转变为整型,再转变为实型的,但是没有直接从字符串转变为实型的方法,好像是由于系统不能把小数点识别进去的缘故,如果这样的话,我输入的是小数,就没办法计算平方了。如果是计算小数呢?怎么办?
procedure TForm1.Button1Click(Sender: TObject);
var
a1,b1,c1:string;
a2,b2:single;

begin
if edit1.Text :='' then
showmessage(‘你好!请输入数字’)
else
a1:=edit1.Text
a2:= strtoint64(a1);
b2:=a2*a2;
edit2.Text :='b2'
end;

if edit1.Text :='' then
edit1.Text :='' 这是赋值,不能作判断.
edit2.Text :='b2'实际上edit2.text的值是'b2',而不是你申请的变量b2的值
其实可以这样写.

try
strtofloat(edit1.text)
except
showmessage('请输入数字');
exit;
end;
edit1.text:= floattostr(strtoFloat(edit1.text)*strtofloat(edit1.text));

1.
if edit1.text = '' then

2.
strtofloat
floattostr