# how to count the order of a image list?

Hello guys

I have a panel with 7 images, with this panel I can exchange the images among them, but I need that all those images be in the order by picture.

For each image I gave a number in its tag from 1 to 7

How can I count all images that is in my panel and knows if they are in correct order from 1 to 7 and not different of these?

I attached an example with a panel with images.

This is a part of this thread

Thread with card and drag and drop

thanks
Alexandre
OrderCount.zip
LVL 1
###### Who is Participating?

Commented:
I use simple sorting of image position (X) and after that check is order of index (Tag) is ok.

``````function TForm1.IsCorrectOrder(pnl: TPanel): Boolean;
var
i, j: Integer;
ar: array of TPoint;
pt: TPoint;
begin
//default - if found incorrect one then flag will be set to False
Result := True;
SetLength(ar, pnl.ControlCount);

for i := 0 to pnl.ControlCount-1 do
begin
ar[i].X := pnl.Controls[i].Left; //keep x pos
ar[i].Y := pnl.Controls[i].Tag;  //keep assoc. tag
end;

//try to sort array
for i := High(ar) downto Low(ar) do
begin
for j := Low(ar) to High(ar) - 1 do
begin
if ar[j].X > ar[j + 1].X then
begin
pt := ar[j];
ar[j] := ar[j + 1];
ar[j + 1] := pt;
end;
end;
end;

//check order - compare if first is lower than next
j := 0;
for i := Low(ar) to High(ar) do
begin
if (ar[i].Y < j) then
begin
Result := False;
Break;
end;
j := ar[i].Y; //keep this
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if IsCorrectOrder(Panel3) then
ShowMessage('ok')
else
ShowMessage('not ok');
end;
``````
0

Author Commented:
Very interesting, I am gonna check that.

Once again, Thanks Sinisav for your help. Yesterday I was thinking about that and I didn't get any solution. What you told me, open my mind about. :)
0

Author Commented:
Your code is ok.
0

Author Commented:
Thanks very much Sinisav.

God always bless you :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.