Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi VirtualStringTree and a Queue (https://www.delphipraxis.net/176390-virtualstringtree-queue.html)

sdean 1. Sep 2013 21:41

Delphi-Version: 7

VirtualStringTree and a Queue
 
Hi i've a project that uses the VirtualStringTree , with this Record :

Delphi-Quellcode:
type

  TStudentsSession = record
    StudentName : String;
    StudentClass : String;
    StudentHandRaised:Boolean;

  end;
And i've these Procedures :

Delphi-Quellcode:
Procedure TMainForm.StudentHandRaised(AStudentName:String)
var
    Node:PVirtualNode;
    Data:^TStudentsSession;
begin
    Node:=StudentsVst.GetFirst;
    while Node<>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.StudentHansDown(AStudentName:String)
var
    Node:PVirtualNode;
    Data:^TStudentsSession;
begin
    Node:=StudentsVst.GetFirst;
    while Node<>nil do begin
      Data:=StudentsVst.GetNodeData(Node);
      if Data.StudentName=AStudentName then
        begin
          Data.StudentHandRaised:=False;
          Break;
        end ;
       Node:=StudentsVst.GetNext(Node);
  end;
  end;


We Have these 4 Students in Order:
StudentA
StudentB
StudentC
StudentD


What i want is this :

* StudentB raises his Hand :

StudentB
StudentA
StudentC
StudentD


* StudentC raises his Hand :

StudentB
StudentC
StudentA
StudentD


StudentC will not Jump on StudentB ( Because StudentB is still raising his Hand )

* StudentD raises his Hand :

StudentB
StudentC
StudentD
StudentA


StudentC will not Jump on StudentB or StudentC ( Because both are still raising their Hands )

* StudentB withdraws his hand :


StudentC
StudentD
StudentA
StudentB


* StudentB will be moved to the last position


I tried to use this procedure :

Delphi-Quellcode:
procedure TMainForm.ReArrangeStudents;
var
    Node,PreviNode: PVirtualNode;
    Data:^TStudentsSession;
begin
  Node:=StudentsVst.GetFirst;
  while Node<>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;

But this ends with always jumping to the First position .
So please can some one helps me to Do the correct Order .


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz