unit phTriState; interface type TriState_=(tsFalse=0, tsTrue=1,tsNull=2); TriState=record private value:TriState_; public class operator Implicit(v:TriState):Boolean; class operator Implicit(v:TriState_):TriState; class operator Implicit(v:boolean):TriState; class operator Equal(my:Tristate; their:Boolean):Boolean; class operator Equal(my:Tristate; their:TriState_):Boolean; class operator LogicalAnd(my: TriState; b: boolean): TriState; class operator LogicalAnd(my: TriState; b: TriState): TriState; class operator Explicit(v:TriState):Boolean; end; implementation { TriState } class operator TriState.Equal(my: Tristate; their: TriState_): Boolean; begin Result:=my.value=their; end; class operator TriState.Explicit(v: TriState): Boolean; begin result:=v end; class operator TriState.Equal(my: Tristate; their: Boolean): Boolean; begin result:= (Ord(my.value)=Ord(their)) end; class operator TriState.Implicit(v: TriState): Boolean; begin result:= (v.value<>tsNull) and (Boolean(v.value)); end; class operator TriState.Implicit(v: boolean): TriState; begin result.value:=TRistate_(Ord(v)); end; class operator TriState.LogicalAnd(my, b: TriState): TriState; begin if (my.value=tsNull) or (b.value=tsNull) then Result.value:=tsNull else Result.value:=Tristate_(Boolean(ord(my.value)) and Boolean(Ord(b.value))); end; class operator TriState.LogicalAnd(my: TriState; b: boolean): TriState; var nv:Tristate; begin nv:=b; result:= my and nv; end; class operator TriState.Implicit(v: TriState_): TriState; begin Result.value:=v; end; end. |