gpt4 book ai didi

Delphi if else if else 语句不起作用 "Type of expression must be BOOLEAN"

转载 作者:行者123 更新时间:2023-12-03 15:38:59 25 4
gpt4 key购买 nike

我正在尝试用 Delphi 制作一个货币转换器,自从我上次使用 Delphi 以来已经有一段时间了,所以我有点生疏了。当我尝试创建 if、else if、else 语句时,它给出错误:“表达式类型必须是 BOOLEAN”。

这是我的代码:

if Edit1.Text = '' And Edit2.Text <> ''
then Edit2.Text := '1'
else
if Edit1.Text <> '' And Edit2.Text = ''
then ShowMessage('Blah')
else
if Edit1.Text ='' And Edit2.Text = ''
then ShowMessage('Please Enter A Value')
else
ShowMessage('Mathing Suff...');

如果有人能看到我的愚蠢错误或出了什么问题,那将会有很大帮助。 :)

编辑:错误出现在第一个 if 语句及其后面的两个 else if 的行上。

最佳答案

这是因为运算符优先级,您应该将每个条件放在括号中

试试这个代码

if (Edit1.Text = '') And (Edit2.Text <> '')  then 
Edit2.Text := '1'
else
if (Edit1.Text <> '') And (Edit2.Text = '') then
ShowMessage('Blah')
else
if (Edit1.Text ='') And (Edit2.Text = '')then
ShowMessage('Please Enter A Value')
else
ShowMessage('Mathing Suff...');

关于Delphi if else if else 语句不起作用 "Type of expression must be BOOLEAN",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17055816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com