Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1.     void TMainForm::SortGrid(int Col, Direction Dir)
  2.     {
  3.         TStringList *buf = new TStringList;
  4.         bool b = true;
  5.         while (b)
  6.         {
  7.             b = false;
  8.             for (int i = 1; i < StringGrid->RowCount - 1; i++)
  9.             {
  10.                 int sign;
  11.                 try
  12.                 {
  13.                     if (Dir == dirDown) sign = StringGrid->Cells[Col][i].ToInt() > StringGrid->Cells[Col][i + 1].ToInt();
  14.                     else sign = StringGrid->Cells[Col][i].ToInt() < StringGrid->Cells[Col][i + 1].ToInt();
  15.                 }
  16.                 catch (EConvertError &error)
  17.                 {
  18.                     if ((StringGrid->Cells[Col][i] == "" || StringGrid->Cells[Col][i+1] == "") && StringGrid->Cells[Col][i] != StringGrid->Cells[Col][i+1] ) sign = true;
  19.                     else if (Dir == dirDown) sign = StringGrid->Cells[Col][i] > StringGrid->Cells[Col][i + 1];
  20.                     else sign = StringGrid->Cells[Col][i] < StringGrid->Cells[Col][i + 1];
  21.                 }
  22.                 if (sign)
  23.                 {
  24.                     buf->Assign(StringGrid->Rows[i]);
  25.                     StringGrid->Rows[i]->Assign(StringGrid->Rows[i + 1]);
  26.                     StringGrid->Rows[i + 1]->Assign(buf);
  27.                     b = true;
  28.                 }
  29.             }    
  30.         }
  31.             delete buf;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement