
29.01.2014, 09:30
|
Прохожий
|
|
Регистрация: 19.08.2011
Сообщения: 28
Репутация: 10
|
|
Если вдруг кому-то поможет. Вот решение:
Код:
procedure TForm1.Button2Click(Sender: TObject);
var
TS : TStringList;
i, indexS : integer;
begin
TS := TStringList.Create;
for i:=1 to StringGrid1.RowCount-1 do begin
indexS := TS.IndexOf(StringGrid1.Cells[2,i]);
if indexS<0 then begin {ещё не было такой строки, добавляем}
TS.AddObject(StringGrid1.Cells[2,i], TObject(1));
end
else {такое значение уже было ранее, увеличим счётчик на 1}
TS.Objects[indexS] := TObject(Integer(TS.Objects[indexS])+1);
end;
StringGrid2.RowCount := TS.Count+1;
for I := 0 to TS.Count - 1 do begin
StringGrid2.Cells[0,i+1] := IntToStr(i+1);
StringGrid2.Cells[1,i+1] := TS.Strings[i];
StringGrid2.Cells[2,i+1] := IntToStr( Integer(TS.Objects[i]));
end;
FreeAndNil(TS);
end;
|