In Delphi XE2, I'm trying to overload the in operator on a record to allow me to check whether the value represented by the record is part of a set. My code looks like this:
type
MyEnum = (value1, value2, value3);
MySet = set of MyEnum;
MyRecord = record
Value: MyEnum;
class operator In(const A: MyRecord; B: MySet): Boolean;
end;
class operator MyRecord.In(const A: MyRecord; B: MySet): Boolean;
begin
Result := A.Value in B;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
R: MyRecord;
S: MySet;
begin
R.Value := value1;
S := [value1, value2];
Button1.Caption := BoolToStr(R in S);
end;
The code fails to compile. For the statement R in S the compiler says: Incompatible types MyRecord and MyEnum.
How can I overload the In operator on MyRecord so that R in S will evaluate to True in the above code?
function InSet(S: MySet): Booleanto the record and use that instead of theinoperator. - Jan GoyvaertsBoolToStr(R._in(S));- Arioch 'The