Лидеры рейтинга
Мастер-Эксперт
1097
Академик
419
Мастер-Эксперт
397
Мастер-Эксперт
330
Советник
99
Профессионал
50
Профессор
44
8.1.6
02.01.2021
JS: 2.2.2
CSS: 4.2.0
jQuery: 3.5.1
Создание программ на языках Pascal, Delphi и Lazarus.
Администратор раздела: Зенченко Константин Николаевич (Старший модератор)
|
Перейти к консультации №: |
|
Здравствуйте! Прошу помощи в следующем вопросе:
Есть таблица stringgrid, помогите сделать сортировку. Выдать список по заданной пользователем стране и количеству дней выше введенных пользователем, отсортированный по сумма к оплате.
Delphi
-----
Прикрепленное изображение (кликните по картинке для увеличения):
Состояние: Консультация закрыта
Здравствуйте, Ericsson!
Код Delphi 6:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) StringGrid1: TStringGrid; ComboBox1: TComboBox; Edit1: TEdit; StringGrid2: TStringGrid; procedure FormCreate(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } ListData:TStringList; ChangeBox,ChangeEdit:boolean; procedure SortGrid; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.SortGrid; var a,b,c:integer; d:string; begin a:=StrToInt(Form1.Edit1.Text); Form1.StringGrid1.Visible:=false; Form1.StringGrid2.Top:=Form1.StringGrid1.Top; Form1.StringGrid2.Left:=Form1.StringGrid1.Left; Form1.StringGrid2.Width:=Form1.StringGrid1.Width; Form1.StringGrid2.Height:=Form1.StringGrid1.Height; Form1.StringGrid2.ColCount:=Form1.StringGrid1.ColCount; Form1.StringGrid2.RowCount:=0; for c:=1 to Form1.StringGrid1.RowCount-1 do begin if(Form1.StringGrid1.Cells[2,c]=Form1.ComboBox1.Items[Form1.ComboBox1.ItemIndex])and (a<=StrToInt(Form1.StringGrid1.Cells[3,c])) then begin Form1.StringGrid2.RowCount:=Form1.StringGrid2.RowCount+1; for b:=0 to form1.StringGrid1.ColCount-1 do Form1.StringGrid2.Cells[b,Form1.StringGrid2.RowCount-1]:=Form1.StringGrid1.Cells[b,c]; end; end; Form1.StringGrid2.Visible:=true; ShowMessage('sorting'); for a:=1 to Form1.StringGrid2.RowCount-2do for b:=a+1 to Form1.StringGrid2.RowCount-1do if StrToFloat(Form1.StringGrid2.Cells[8,a])<StrToFloat(Form1.StringGrid2.Cells[8,b])then for c:=0 to Form1.StringGrid2.ColCount-1 do begin d:=Form1.StringGrid2.Cells[c,a]; Form1.StringGrid2.Cells[c,a]:=Form1.StringGrid2.Cells[c,b]; Form1.StringGrid2.Cells[c,b]:=d; end; end; procedure TForm1.FormCreate(Sender: TObject); var a:double; i,j:integer; s:string; begin s:='D:\CAT\_my\201207.txt'; ListData:=Tstringlist.Create; ListData.Clear; ListData.Sorted:=false; ListData.LoadFromFile(s); Form1.StringGrid1.RowCount:=ListData.Count+1; Form1.StringGrid1.Visible:=false; Form1.StringGrid2.Visible:=false; for i:=0 to ListData.Count-1 do begin s:=ListData.Strings[i]+' '; j:=0; while length(s)>0 do begin while s[1]=' 'do delete(s,1,1); Form1.StringGrid1.Cells[j,i+1]:=copy(s,1,pos(' ',s)-1); delete(s,1,pos(' ',s)); inc(j); end; a:=StrToInt(Form1.StringGrid1.Cells[3,i+1])* (StrToInt(Form1.StringGrid1.Cells[5,i+1])*StrToInt(Form1.StringGrid1.Cells[7,i+1])+ 0.7*StrToInt(Form1.StringGrid1.Cells[6,i+1])*StrToInt(Form1.StringGrid1.Cells[7,i+1]) ); Form1.StringGrid1.Cells[8,i+1]:=Format('%f',[a]); end; ListData.Clear; Form1.StringGrid1.Visible:=true; ListData.Sorted:=true; for i:=1 to Form1.StringGrid1.RowCount-1 do if not ListData.Find(Form1.StringGrid1.Cells[2,i],j) then ListData.Add(Form1.StringGrid1.Cells[2,i]); Form1.ComboBox1.Items.BeginUpdate; Form1.ComboBox1.Clear; Form1.ComboBox1.Items.AddStrings(ListData); Form1.ComboBox1.Items.EndUpdate; ListData.Free; Form1.ChangeBox:=false; Form1.ChangeEdit:=false; end; procedure TForm1.ComboBox1Change(Sender: TObject); begin if ChangeEdit then SortGrid else ChangeBox:=true; end; procedure TForm1.Edit1Change(Sender: TObject); begin if ChangeBox then SortGrid else ChangeEdit:=true; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not( Key in ['0'..'9',#13] )then Key:=#0; end; end.
|
Консультировал: Зенченко Константин Николаевич (Старший модератор) Дата отправки: 08.12.2020, 14:25
5
нет комментария----- Дата оценки: 08.12.2020, 15:18 |
Рейтинг ответа:
+1 Сообщение модераторам Отправлять сообщения |
Возможность оставлять сообщения в мини-форумах консультаций доступна только после входа в систему.
Воспользуйтесь кнопкой входа вверху страницы, если Вы зарегистрированы или пройдите простую процедуру регистрации на Портале.