Solved

how to count the order of a image list?

Posted on 2013-11-25
4
357 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:hidrau
  • 3
4 Comments
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39676865
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;

Open in new window

0
 
LVL 1

Author Comment

by:hidrau
ID: 39677208
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
 
LVL 1

Author Comment

by:hidrau
ID: 39679338
Your code is ok.
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39679438
Thanks very much Sinisav.

God always bless you :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 206
Mydac connection data base issue 3 140
Delphi: how to send PJL commands to printer 3 90
Delphi XE10 Round Image 2 79
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now