Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  4 796

•  TDictionary Custom Sort  6 793

•  Fast Watermark Sources  6 581

•  3D Designer  9 534

•  Sik Screen Capture  6 918

•  Patch Maker  7 365

•  Айболит (remote control)  7 303

•  ListBox Drag & Drop  6 168

•  Доска для игры Реверси  98 108

•  Графические эффекты  7 481

•  Рисование по маске  6 774

•  Перетаскивание изображений  5 630

•  Canvas Drawing  6 007

•  Рисование Луны  5 798

•  Поворот изображения  5 251

•  Рисование стержней  3 843

•  Paint on Shape  2 999

•  Генератор кроссвордов  3 955

•  Головоломка Paletto  3 138

•  Теорема Монжа об окружностях  3 969

•  Пазл Numbrix  2 620

•  Заборы и коммивояжеры  3 431

•  Игра HIP  2 347

•  Игра Go (Го)  2 264

•  Симулятор лифта  2 664

•  Программа укладки плитки  2 225

•  Генератор лабиринта  2 775

•  Проверка числового ввода  2 385

•  HEX View  2 720

•  Физический маятник  2 411

 
скрыть

Сортировка TStringGrid



Оформил: DeeCo

procedure SortStringGrid(var GenStrGrid: TStringGrid; ThatCol: Integer);
 const
   // Define the Separator 
  TheSeparator = '@';
 var
   CountItem, I, J, K, ThePosition: integer;
   MyList: TStringList;
   MyString, TempString: string;
 begin
   // Give the number of rows in the StringGrid 
  CountItem := GenStrGrid.RowCount;
   //Create the List 
  MyList        := TStringList.Create;
   MyList.Sorted := False;
   try
     begin
       for I := 1 to (CountItem - 1) do
         MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator +
           GenStrGrid.Rows[I].Text);
       //Sort the List 
      Mylist.Sort;

       for K := 1 to Mylist.Count do
       begin
         //Take the String of the line (K – 1) 
        MyString := MyList.Strings[(K - 1)];
         //Find the position of the Separator in the String 
        ThePosition := Pos(TheSeparator, MyString);
         TempString  := '';
         {Eliminate the Text of the column on which we have sorted the StringGrid}
         TempString := Copy(MyString, (ThePosition + 1), Length(MyString));
         MyList.Strings[(K - 1)] := '';
         MyList.Strings[(K - 1)] := TempString;
       end;

       // Refill the StringGrid 
      for J := 1 to (CountItem - 1) do
         GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];
     end;
   finally
     //Free the List 
    MyList.Free;
   end;
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   // Sort the StringGrid1 on the second Column 
  // StringGrid1 nach der 1. Spalte sortieren 
  SortStringGrid(StringGrid1, 1);
 end;