开发者

Pascal: "or" not supported for types "Char"

I'm new here so sorry if I do som开发者_开发问答ething 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!


or has to be used with Boolean expressions, like

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


Must use AND operator:

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

(Don't use OR operator in this case)


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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜