IN keyword with Dynamic Array



"in" keyword
Pas2JS pascal source code
type TRec = record x: Integer; y: string; end; const r1: TRec = (x: 1; y: 'one'); r2: TRec = (x: 2; y: 'two'); r3: TRec = (x: 2; y: 'twobis'); { unit1.pas} var recs: array of TRec; ints: array of Integer; objs: array of TObject; o := New TObject; begin ints.Add(1); ints.Add(2); Writeln('Integers'); // Integers Writeln(0 in ints); // False Writeln(1 in ints); // True Writeln(2 in ints); // True Writeln(0 not in ints); // True Writeln(1 not in ints); // False Writeln(2 not in ints); // False Writeln('Records'); // Records recs.Add(r1); // True recs.Add(r2); // True Writeln(r1 in recs); // true Writeln(r2 in recs); // true Writeln(r3 in recs); // false objs.Add(TObject.Create); objs.Add(o); Writeln('Objects'); // Objects Writeln(TObject.Create in objs); // False Writeln(o in objs); // True { unit2.pas} var list: array of Integer = [5, 7]; item: variant = 5; begin if item in list then Writeln('success')else Writeln('fail'); if not item in list then Writeln('bug'); if not 5 in list then Writeln('bug'); if not (not 5) in list then Writeln('ok'); { success ok }