当我使用这两种代码运行应用程序时,会显示相同的错误:
运算符不适用于此操作数类型。
procedure TForm1.Button4Click(Sender: TObject);
begin
If (shape1.Brush.Color:=clblue and shape2.Brush.Color:=clblue) then
begin
showMessage('error');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
If (shape1.Brush.Color:=clblue) and (shape2.Brush.Color:=clblue) then
begin
showMessage('error');
end;发布于 2014-02-04 00:19:32
这里有两个问题。
首先,正在使用的操作符:=是赋值,而不是等式检查。为此,你想要=。
第二,由于and和or运算符的优先级问题,同一表达式中的多个比较需要在每个单独的比较中加上括号。你想要的是:
if (shape1.Brush.Color = clblue) and (shape2.Brush.Color = clblue) then
begin
showMessage('error');
end;发布于 2014-02-04 00:11:47
你应该重读你的德尔菲手册!
等式的比较是一个简单的=,而:=用于赋值。
https://stackoverflow.com/questions/21540187
复制相似问题