title: Delphi VirtualStringTree and a Queue
body: <p>Hi i've a project that uses the VirtualStringTree , with this Record :</p>
  
  <pre><code>type
    TStudentsSession = record
      StudentName : String;
      StudentClass : String;
      StudentHandRaised:Boolean;
    end;
  </code></pre>
  
  <p>And i've these Procedures :</p>
  
  <pre><code>Procedure TMainForm.StudentHandRaised(AStudentName: String)
  var
    Node: PVirtualNode;
    Data: ^TStudentsSession;
  begin
    Node := StudentsVst.GetFirst;
    while Node &lt;&gt; nil do
    begin
      Data := StudentsVst.GetNodeData(Node);
      if Data.StudentName = AStudentName then
      begin
        Data.StudentHandRaised := True;
        Break;
      end;
      Node := StudentsVst.GetNext(Node);
    end;
  end;
  
  Procedure TMainForm.StudentHandsDown(AStudentName: String)
  var
    Node: PVirtualNode;
    Data: ^TStudentsSession;
  begin
    Node := StudentsVst.GetFirst;
    while Node &lt;&gt; nil do
    begin
      Data := StudentsVst.GetNodeData(Node);
      if Data.StudentName = AStudentName then
      begin
        Data.StudentHandRaised := False;
        Break;
      end;
      Node := StudentsVst.GetNext(Node);
    end;
  end;
  </code></pre>
  
  <p>We Have these 4 Students in Order: </p>
  
  <ul>
  <li><strong>StudentA</strong></li>
  <li><strong>StudentB</strong></li>
  <li><strong>StudentC</strong></li>
  <li><strong>StudentD</strong></li>
  </ul>
  
  <p>What i want is this :</p>
  
  <p>1 : StudentB raises his Hand :</p>
  
  <ul>
  <li><strong>StudentB</strong></li>
  <li><strong>StudentA</strong></li>
  <li><strong>StudentC</strong></li>
  <li><strong>StudentD</strong></li>
  </ul>
  
  <p>2 : StudentC raises his Hand :</p>
  
  <ul>
  <li><strong>StudentB</strong></li>
  <li><strong>StudentC</strong></li>
  <li><strong>StudentA</strong></li>
  <li><strong>StudentD</strong></li>
  </ul>
  
  <p>StudentC will not Jump on StudentB ( Because StudentB is still raising his Hand )</p>
  
  <p>3 : StudentD raises his Hand :</p>
  
  <ul>
  <li><strong>StudentB</strong></li>
  <li><strong>StudentC</strong></li>
  <li><strong>StudentD</strong></li>
  <li><strong>StudentA</strong></li>
  </ul>
  
  <p>StudentC will not Jump on StudentB or StudentC ( Because both are still raising their Hands )</p>
  
  <p>4 : StudentB withdraws his hand :</p>
  
  <ul>
  <li><strong>StudentC</strong></li>
  <li><strong>StudentD</strong></li>
  <li><strong>StudentA</strong></li>
  <li><strong>StudentB</strong></li>
  </ul>
  
  <p>StudentB will be moved to the last position  </p>
  
  <p>I tried to use this procedure :</p>
  
  <pre><code>procedure TMainForm.ReArrangeStudents;
  var
    Node, PreviNode: PVirtualNode;
    Data: ^TStudentsSession;
  begin
    Node := StudentsVst.GetFirst;
    while Node &lt;&gt; nil do
    begin
      Data := StudentsVst.GetNodeData(Node);
      if Data.StudentHandRaised then
        PreviNode := StudentsVst.GetPrevious(Node, False)
      else
        PreviNode := StudentsVst.GetNext(Node);
      StudentsVst.MoveTo(Node, PreviNode, amInsertBefore, False);
      Node := StudentsVst.GetNext(Node);
    end;
  end;
  </code></pre>
  
  <p>Thank you all</p>