use*_*883 0 delphi if-statement brush colors shape
当我使用这两个代码运行应用程序时,显示相同的错误:
运算符不适用于此操作数类型
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;
Run Code Online (Sandbox Code Playgroud)
这里有两个问题.
首先,正在使用的运算符:=
是赋值,而不是相等性检查.为此,你想要=
.
其次,由于and
与or
运算符的优先级问题,同一表达式中的多重比较需要围绕每个单独的比较进行括号.所以你想要的是:
if (shape1.Brush.Color = clblue) and (shape2.Brush.Color = clblue) then
begin
showMessage('error');
end;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1172 次 |
最近记录: |