![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
![]() нужно чтоб цифры переносилось с помощью кнопки из Memo в StringGrid и упорядочивалось по возрастанию.
Заранее благодарен! |
#2
|
||||
|
||||
![]() Непонятно в каком формате у вас в Мемо лежит текст. Что является разделителем и соответственно критерием расстановки по ячейкам.
Жизнь такова какова она есть и больше никакова. Помогаю за спасибо. |
#3
|
|||
|
|||
![]() там цифры, разделяется пробелом. файл .txt
надо чтоб цифры по возрастанию выстраивались в стринггрид Последний раз редактировалось skabl, 17.04.2009 в 00:27. |
#4
|
|||
|
|||
![]() Вот, пожалуй, наипростейший способ.
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } procedure SortCols; procedure SortRows; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var SList: TStringList; i: Integer; begin SList := TStringList.Create; SList.Delimiter := ' '; try for i := 0 to Memo1.Lines.Count - 1 do begin SList.DelimitedText := Memo1.Lines.Strings[i]; StringGrid1.Rows[i].Delimiter := SList.Delimiter; StringGrid1.Rows[i].DelimitedText := SList.DelimitedText; end; SortCols(); // отсортирует по возрастанию столбцы... { SortRows(); // ...или строки (раскомментируйте, если надо) } finally SList.Free; end; end; procedure TForm1.SortCols; var SList: TStringList; i: Integer; begin SList := TStringList.Create; SList.Delimiter := '|'; try for i := 0 to StringGrid1.ColCount - 1 do begin StringGrid1.Cols[i].Delimiter := '|'; SList.DelimitedText := StringGrid1.Cols[i].DelimitedText; SList.Sort; StringGrid1.Cols[i].DelimitedText := SList.DelimitedText; end; finally SList.Free; end; end; procedure TForm1.SortRows; var SList: TStringList; i: Integer; begin SList := TStringList.Create; SList.Delimiter := '|'; try for i := 0 to StringGrid1.RowCount - 1 do begin StringGrid1.Rows[i].Delimiter := '|'; SList.DelimitedText := StringGrid1.Rows[i].DelimitedText; SList.Sort; StringGrid1.Rows[i].DelimitedText := SList.DelimitedText; end; finally SList.Free; end; end; end. Последний раз редактировалось Nyctos Kasignete, 17.04.2009 в 10:09. |
#5
|
|||
|
|||
![]() чеи странно, в последовательность не ставит
|
#6
|
|||
|
|||
![]() skabl, так вы чей вариант-то используете? И что значит
Цитата:
|
#8
|
|||
|
|||
![]() Цитата:
Может это поможет : Код:
procedure StringGrid_SortCol(SG : TStringGrid; HideSGBefore : boolean; ACol : integer; TypeCol : integer; NrOpt : integer = 0); {Сортировка по заданному столбцу} Var Vis,YesGreate : Boolean; X1,X2 : real; I1,I2 : integer; dd,mm,yyyy : integer; S1,S2,S0 : string; ListS : TStrings; Res,N,k,j,i : LongInt; begin if SG<>NIL then begin if SG.RowCount>1 then begin if (ACol>=0) and (ACol<SG.ColCount) then begin Vis:=SG.Visible; if HideSGBefore then SG.Visible:=FALSE; ListS:=TStringList.Create; TRY N:=SG.RowCount-1; for i:=1 to N do begin k:=N-i; for j:=1 to k do begin YesGreate := FALSE; S1:=SG.Cells[ACol,j]; S2:=SG.Cells[ACol,j+1]; S1:=Trim(S1); S2:=Trim(S2); {[1,6,11,14]} if TypeCol=(-1) then begin //тип столбца : строка UpCase S1:=AnsiUpperCase(S1); S2:=AnsiUpperCase(S2); if S1>S2 then begin YesGreate := TRUE; end; end; if TypeCol=0 then begin //тип столбца : строка if S1>S2 then begin YesGreate := TRUE; end; end; if TypeCol=1 then begin //тип столбца : число Val(S1,X1,Res); Val(S2,X2,Res); if X1>X2 then begin YesGreate := TRUE; end; end; if TypeCol=2 then begin //тип столбца : дата (dd.mm.yyyy) if NrOpt<=0 then begin if GetIDDateS_0(S1)>GetIDDateS_0(S2) then begin YesGreate := TRUE; end; end else begin dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,1),0); //День mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,2),0); //Мес yyyy:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,3),0); //Год I1:=GetIDDate(yyyy,mm,dd); dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,1),0); //День mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,2),0); //Мес yyyy:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,3),0); //Год I2:=GetIDDate(yyyy,mm,dd); if I1>I2 then begin YesGreate := TRUE; end; end; end; if TypeCol=3 then begin //тип столбца : неполная дата (dd.mm) if NrOpt<=0 then begin if GetIDMDS(S1)>GetIDMDS(S2) then begin YesGreate := TRUE; end; end else begin dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,1),0); //День mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,2),0); //Мес I1:=GetIDMD(mm,dd); dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,1),0); //День mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,2),0); //Мес I2:=GetIDMD(mm,dd); if I1>I2 then begin YesGreate := TRUE; end; end; end; if YesGreate then begin ListS.Assign(SG.Rows[j]); SG.Rows[j].Assign(SG.Rows[j+1]); SG.Rows[j+1].Assign(ListS); end; end; end; FINALLY if ListS<>NIL then begin ListS.Free; end; ListS:=NIL; SG.Visible:=Vis; END; end; end; end; end; Последний раз редактировалось Admin, 17.04.2009 в 10:24. |