Add function GetEnumerator to TdwsDebuggerWatches

Issue #258 resolved
Alex Bespalov created an issue

For normal watches enumeration in for…in cycles.

Comments (3)

  1. Alex Bespalov reporter

    P.S. Maybe will be better to show my code :)

             type
                TWatchEnumerator = record
                   private
                      FIndex, FCountMinus1 : Integer;
                      FOwner : TdwsDebuggerWatches;
                   public
                      function MoveNext : Boolean; inline;
                      function GetCurrent : TdwsDebuggerWatch; inline;
                      property Current : TdwsDebuggerWatch read GetCurrent;
                end;
             function GetEnumerator : TWatchEnumerator;
    
    implementation
    
    // GetEnumerator
    //
    function TdwsDebuggerWatches.GetEnumerator : TWatchEnumerator;
    begin
       Result.FIndex:=-1;
       Result.FOwner:=Self;
       Result.FCountMinus1:=Count-1;
    end;
    
    // TWatchEnumerator.GetCurrent
    //
    function TdwsDebuggerWatches.TWatchEnumerator.GetCurrent : TdwsDebuggerWatch;
    begin
       Result:=FOwner.Items[FIndex];
    end;
    
    // TWatchEnumerator.MoveNext
    //
    function TdwsDebuggerWatches.TWatchEnumerator.MoveNext : Boolean;
    begin
       Result:=(FIndex<FCountMinus1);
       Inc(FIndex, Integer(Result));
    end;
    

  2. Log in to comment