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

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

•  TDictionary Custom Sort  6 476

•  Fast Watermark Sources  6 267

•  3D Designer  9 217

•  Sik Screen Capture  6 605

•  Patch Maker  6 991

•  Айболит (remote control)  6 991

•  ListBox Drag & Drop  5 861

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

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

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

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

•  Canvas Drawing  5 736

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

•  Поворот изображения  4 974

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

•  Paint on Shape  2 801

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

•  Головоломка Paletto  2 954

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

•  Пазл Numbrix  2 481

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

•  Игра HIP  2 129

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

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

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

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

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

•  HEX View  2 590

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

 
скрыть

Сортировка 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;