alternative to check, whether a value is in a set

Posted by stanleyxu2005 on Stack Overflow See other posts from Stack Overflow or by stanleyxu2005
Published on 2010-06-07T07:47:57Z Indexed on 2010/06/07 7:52 UTC
Read the original article Hit count: 233

Filed under:
|
|

Hi All,

I have the following code. It looks ugly, if the value equals to one of the following value then do something.

var
  Value: Word;
begin
  Value := 30000;
  if (Value = 30000) or (Value = 40000) or (Value = 1) then
    do_something;
end;

I want to refactor the code as follows:

var
  Value: Word;
begin
  Value := 30000;
  if (Value in [1, 30000, 40000]) then // Does not work
    do_something;
end;

However, the refactored code does not work. I assume that a valid set in Delphi accepts only elements with type byte. If there any good alternative to refactor my original code (besides using case)?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about set