Pascal: "or" is not supported for char types

I'm new here, so sorry if I did something wrong!

I am making a simple Pascal program in Lazarus and I get this error when compiling:

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

Here is part of the complaint:

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!

+3
source share
4 answers

or should be used with boolean expressions such as

(style <> 'e') or (style <> 'mp') or (style <> 'sa')
+6
source

Must use the AND operator:

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

(do not use the OR operator in this case)

+4
source

, .

+2

pascal Sets, (, CHAR, NOT Strings):

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

A very common use case that I often encounter is to detect TDataSet editing:

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

Source: https://habr.com/ru/post/1767253/


All Articles