帕斯卡:“或”不支持类型“Char”

发布于 2024-09-26 02:53:54 字数 322 浏览 4 评论 0原文

我是新来的,如果我做错了什么,很抱歉!

我正在 Lazarus 中制作一个简单的 Pascal 程序,在编译时遇到此错误:

HWE(16,18) 错误:类型“Char”和“常量字符串”不支持操作“或”

这是它抱怨的部分关于:

Repeat
begin
Readln(style);
If style <> ('e' or 'mp' or 'sa') then
Writeln ('do what I say!')
end
Until style = (e or mp or sa); 

感谢您的帮助!

I'm new here so sorry if I do something wrong!

I'm making a simple Pascal program in Lazarus and I'm getting this error when compiling:

HWE(16,18) Error: Operation "or" not supported for types "Char" and "Constant String"

Here is the part it's complaining about:

Repeat
begin
Readln(style);
If style <> ('e' or 'mp' or 'sa') then
Writeln ('do what I say!')
end
Until style = (e or mp or sa); 

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别低头,皇冠会掉 2024-10-03 02:53:54

or 必须与布尔表达式一起使用,例如

(style <> 'e') or (style <> 'mp') or (style <> 'sa')

or has to be used with Boolean expressions, like

(style <> 'e') or (style <> 'mp') or (style <> 'sa')
蓝眼泪 2024-10-03 02:53:54

必须使用 AND 运算符:

If (style <> 'e') AND (style <> 'mp') AND (style <> 'sa') then

(在这种情况下不要使用 OR 运算符)

Must use AND operator:

If (style <> 'e') AND (style <> 'mp') AND (style <> 'sa') then

(Don't use OR operator in this case)

转角预定愛 2024-10-03 02:53:54

使用关系运算符和布尔运算符组合两个布尔表达式时,请小心使用括号。

When combining two Boolean expressions using relational and Boolean operators, be careful to use parentheses.

金兰素衣 2024-10-03 02:53:54

pascal 有一个很好的方法可以使用 Set 来完成此操作,但仅适用于序数类型(例如 CHAR,但不是字符串):

if not(style in ['e', 'm', 'p']) then
  begin
  DoSomething;
  end

我经常遇到的一个非常常见的用例是检测 TDataSet 是否正在编辑:

if MyDataSet.State in [dsEdit, dsInsert] then
  Begin
  DoSomething;
  End;

There is a nice way in pascal to do this using Sets, but for ordinal types only (like CHAR, but NOT Strings):

if not(style in ['e', 'm', 'p']) then
  begin
  DoSomething;
  end

A very common use case I very often come across is to detect if a TDataSet is being edited:

if MyDataSet.State in [dsEdit, dsInsert] then
  Begin
  DoSomething;
  End;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文