would be that?
"ITEMS" is a TStrings/TStringList - then ...
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
LMyItemsString := ['Item01', 'Item02', 'Item03', 'Item04', 'Item05', 'Item06', 'Item07', 'Item08', 'Item09', 'Item10'];
//
ListBox1.Items.AddStrings(LMyItemsString);
ListBox2.Items.AddStrings(LMyItemsString);
end;
function MyAlreadyUsed(Arr: TArray<integer>; Value: integer): boolean;
begin
result := false;
//
for var V in Arr do
if (V = Value) then
exit(true);
end;
procedure MyNewOrderList(ASrcArray: TArray<string>; var ATrgArray: TArray<string>);
var
LPositionAlreadyUsed: TArray<integer>;
LTotalItems : integer;
LRandomPosition : integer;
begin
randomize;
//
LTotalItems := length(ASrcArray);
//
for var i: integer := 0 to (LTotalItems - 1) do
begin
LRandomPosition := random(LTotalItems);
//
if (length(LPositionAlreadyUsed) > 1) then
while MyAlreadyUsed(LPositionAlreadyUsed, LRandomPosition) do
begin
LRandomPosition := random(LTotalItems);
end;
//
LPositionAlreadyUsed := LPositionAlreadyUsed + [LRandomPosition];
// new order...
ATrgArray := ATrgArray + [ASrcArray[LRandomPosition]];
end;
end;
procedure TForm1.Btn_DeOrder_itClick(Sender: TObject);
var
LMyItemsStringOutOfOrder: TArray<string>;
begin
ListBox2.Sorted := false;
//
MyNewOrderList(LMyItemsString, LMyItemsStringOutOfOrder);
//
ListBox2.Items.Clear;
ListBox2.Items.AddStrings(LMyItemsStringOutOfOrder);
//
ListBox1.SetFocus;
end;
procedure TForm1.Btn_Order_itClick(Sender: TObject);
begin
ListBox2.Sorted := true;
ListBox1.SetFocus;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var
i: integer;
begin
i := ListBox1.ItemIndex;
if (i > -1) then
begin
if ListBox1.Items[i] = ListBox2.Items[i] then
ListBox2.ItemIndex := i
else
ListBox2.ItemIndex := -1; // de-Select
end;
end;
end.