Hi i've a project that uses the VirtualStringTree , with this Record :
type
TStudentsSession = record
StudentName : String;
StudentClass : String;
StudentHandRaised:Boolean;
end;
And i've these Procedures :
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.StudentHandsDown(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 :
1 : StudentB raises his Hand :
- StudentB
- StudentA
- StudentC
- StudentD
2 : StudentC raises his Hand :
- StudentB
- StudentC
- StudentA
- StudentD
StudentC will not Jump on StudentB ( Because StudentB is still raising his Hand )
3 : StudentD raises his Hand :
- StudentB
- StudentC
- StudentD
- StudentA
StudentC will not Jump on StudentB or StudentC ( Because both are still raising their Hands )
4 : StudentB withdraws his hand :
- StudentC
- StudentD
- StudentA
- StudentB
StudentB will be moved to the last position
I tried to use this procedure :
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;
Thank you all