- •1)Тема: « Работа с числом. Формирование нового числа».
- •2) Тема: « Работа с компонентами – списки tListBox и tComboBox при обработке линейных массивов »
- •3) Тема: «Работа со списками на форме. Сортировка массива».
- •4)Тема: « Работа с таблицами. Компонент tStringGrid»
- •5)Тема: « Работа с несколькими формами»
- •6)Тема: « Работа с несколькими таблицами.
- •7)Тема: Оpганизация последовательного файла.
- •8) Тема: « Разработка диаграмм».
- •10)Тема: « Разработка проектов »
6)Тема: « Работа с несколькими таблицами.
Компоненты TStringGrid »
Расположить на форме компонент Вкладки и расположить на них 3 таблицы- одну с исходными данными о студенте: ФИО, отделение, курс, стипендия. А во вторую выбирать студентов курса, указанного в окне Edit, в третью выбрать тех студентов, которые получают стипендию на втором курсе .
unit Unit1;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SG1.Cells[0,0]:='ÔÈÎ';
SG1.Cells[1,0]:='Отделение';
SG1.Cells[2,0]:='Êóðñ';
SG1.Cells[3,0]:='Стипендия';
SG2.Cells[0,0]:='ÔÈÎ';
SG2.Cells[1,0]:='Отделение';
SG2.Cells[2,0]:='Стипендия';
SG3.Cells[0,0]:='ÔÈÎ';
SG3.Cells[1,0]:='Отделение';
SG3.Cells[2,0]:='Êóðñ';
end;
procedure TForm1.Button2Click(Sender: TObject);
var j,i:byte;
begin
for j:=0 to sg1.colcount-1 do
for i:=1 to sg1.rowcount-1 do
SG1.Cells[j,i]:='';
for j:=0 to sg2.colcount-1 do
for i:=1 to sg2.rowcount-1 do
SG2.Cells[j,i]:='';
for j:=0 to sg3.colcount-1 do
for i:=1 to sg3.rowcount-1 do
SG3.Cells[j,i]:='';
E1.Text:='';
E2.Text:='';
end;
procedure TForm1.Button3Click(Sender: TObject);
VAR i,j,m,n,K,K1:byte;
begin
K:=1;
for i:=1 to SG1.RowCount-1 do
if SG1.Cells[2,i]=E1.Text then begin
SG2.Cells[0,K]:=SG1.Cells[0,i];
SG2.Cells[1,K]:=SG1.Cells[1,i];
SG2.Cells[2,K]:=SG1.Cells[3,i];INC(K);
end;
K1:=1;
for i:=1 to SG1.RowCount-1 do
if SG1.Cells[3,i]=E2.Text then begin
SG3.Cells[0,K1]:=SG1.Cells[0,i];
SG3.Cells[1,K1]:=SG1.Cells[1,i];
SG3.Cells[2,K1]:=SG1.Cells[2,i];INC(K1);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if savedialog1.execute=true then
begin
k:=savedialog1.FileName;
assignfile(f,k);
rewrite(f);
writeln(f,SG1.rowcount);
writeln(f,SG1.colcount);
for i:=0 to SG1.rowcount-1 do
for j:=0 to SG1.colcount-1 do
writeln(f,SG1.Cells[j,i]);
closefile(f);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var i,j,n,m:integer; f:textfile;k,t:string;
begin
if opendialog1.execute=true then
begin
k:=opendialog1.FileName;
assignfile(f,k);
reset(f);
readln(f,n);
SG1.Rowcount:=n;
readln(f,m);
SG1.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do begin
readln(f,k);
SG1.Cells[j,i]:=k;
end;
closefile(f);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
end.
7)Тема: Оpганизация последовательного файла.
Создать файл OSADKI.TXT по 3 p-нам Ростовской обл. за год на основании данных о сpеднемесячном кол-ве выпавших осадков и о сpеднемесячной темпеpатуpе воздуха по каждому из p-нов.
unit Unit1;
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.N1Click(Sender: TObject);
var i,j:byte;
begin
for j:=1 to T1.ColCount do
for i:=1 to T1.RowCount do begin
T1.Cells[j,i]:='';
T2.Cells[j,i]:='';
T3.Cells[j,i]:='';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
T1.Cells[0,0]:='Месяц';
T1.Cells[0,1]:='Январь';
T1.Cells[0,2]:='Февраль';
T1.Cells[0,3]:='Ìàðò';
T1.Cells[0,4]:='Апрель';
T1.Cells[0,5]:='Ìàé';
T1.Cells[0,6]:='Èþíü';
T1.Cells[0,7]:='Èþëü';
T1.Cells[0,8]:='Август';
T1.Cells[0,9]:='Сентябрь';
T1.Cells[0,10]:='Октябрь';
T1.Cells[0,11]:='Ноябрь';
T1.Cells[0,12]:='Декабрь';
T1.Cells[1,0]:='сpеднемесячное кол. выпавших осадков ';
T1.Cells[2,0]:='сpеднемесячная темпеpатуpа воздуха ';
T2.Cells[0,0]:='Месяц';
T2.Cells[0,1]:='Январь';
T2.Cells[0,2]:='Февраль';
T2.Cells[0,3]:='Ìàðò';
T2.Cells[0,4]:='Апрель';
T2.Cells[0,5]:='Ìàé';
T2.Cells[0,6]:='Èþíü';
T2.Cells[0,7]:='Èþëü';
T2.Cells[0,8]:='Август';
T2.Cells[0,9]:='Сентябрь';
T2.Cells[0,10]:='Октябрь';
T2.Cells[0,11]:='Ноябрь';
T2.Cells[0,12]:='Декабрь';
T2.Cells[1,0]:='сpеднемесячное кол. выпавших осадков ';
T2.Cells[2,0]:='сpеднемесячная темпеpатуpа воздуха ';
T3.Cells[0,0]:='Месяц';
T3.Cells[0,1]:='Январь';
T3.Cells[0,2]:='Февраль';
T3.Cells[0,3]:='Ìàðò';
T3.Cells[0,4]:='Апрель';
T3.Cells[0,5]:='Ìàé';
T3.Cells[0,6]:='Èþíü';
T3.Cells[0,7]:='Èþëü';
T3.Cells[0,8]:='Август';
T3.Cells[0,9]:='Сентябрь';
T3.Cells[0,10]:='Октябрь';
T3.Cells[0,11]:='Ноябрь';
T3.Cells[0,12]:='Декабрь';
T3.Cells[1,0]:='сpеднемесячное кол. выпавших осадков ';
T3.Cells[2,0]:='сpеднемесячнае темпеpатуpа воздуха ';
T4.Cells[0,0]:='Месяцы';
T4.Cells[1,0]:='сpеднемесячное кол. выпавших осадков ';
StringGrid1.Cells[0,0]:='Районы';
StringGrid1.Cells[0,1]:='Первомайский';
StringGrid1.Cells[0,2]:='Пролетарский';
StringGrid1.Cells[0,3]:='Ворошиловский';
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if savedialog1.execute=true then
begin
k:=savedialog1.FileName;
assignfile(f,k);
rewrite(f);
writeln(f,T1.rowcount);
writeln(f,T1.colcount);
for i:=0 to T1.rowcount-1 do
for j:=0 to T1.colcount-1 do
writeln(f,T1.Cells[j,i]);
closefile(f);
showmessage('Данные сохранены');
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if opendialog1.execute=true then begin
k:=opendialog1.FileName;
assignfile(f,k);
reset(f);
readln(f,n);
T1.Rowcount:=n;
readln(f,m);
T1.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do begin
readln(f,k);
T1.Cells[j,i]:=k;end;closefile(f);
showmessage('Данные загруженны');
end;end;
procedure TForm1.Button7Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if savedialog1.execute=true then
begin
k:=savedialog1.FileName;
assignfile(f,k);
rewrite(f);
writeln(f,T2.rowcount);
writeln(f,T2.colcount);
for i:=0 to T2.rowcount-1 do
for j:=0 to T2.colcount-1 do
writeln(f,T2.Cells[j,i]);
closefile(f);
showmessage('Данные сохранены');
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if opendialog1.execute=true then begin
k:=opendialog1.FileName;
assignfile(f,k);
reset(f);
readln(f,n);
T2.Rowcount:=n;
readln(f,m);
T2.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do begin
readln(f,k);
T2.Cells[j,i]:=k;end;closefile(f);
showmessage('Данные загруженны');
end;end;
procedure TForm1.Button11Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if savedialog1.execute=true then
begin
k:=savedialog1.FileName;
assignfile(f,k);
rewrite(f);
writeln(f,T2.rowcount);
writeln(f,T2.colcount);
for i:=0 to T2.rowcount-1 do
for j:=0 to T2.colcount-1 do
writeln(f,T2.Cells[j,i]);
closefile(f);
showmessage('Данные сохранены');
end;
end;
procedure TForm1.Button12Click(Sender: TObject);
var i,j,n,m:byte; f:textfile;k,t:string;
begin
if opendialog1.execute=true then begin
k:=opendialog1.FileName;
assignfile(f,k);
reset(f);
readln(f,n);
T3.Rowcount:=n;
readln(f,m);
T3.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do begin
readln(f,k);
T3.Cells[j,i]:=k;end;closefile(f);
showmessage('Данные загруженны');
end;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button6Click(Sender: TObject);
var j,i:byte;
begin
for j:=0 to t1.colcount-1 do
for i:=1 to t1.rowcount-1 do
t1.Cells[j,i]:='';
for j:=0 to t2.colcount-1 do
for i:=1 to t2.rowcount-1 do
t2.Cells[j,i]:='';
for j:=0 to t3.colcount-1 do
for i:=1 to t3.rowcount-1 do
t3.Cells[j,i]:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var j,i,sum:byte;
begin
sum:=0;
for i:=1 to T1.RowCount-1 do begin
sum:=sum+strtoint(T1.cells[1,i]); end;
E1.text:=inttostr(sum);
end;
procedure TForm1.Button9Click(Sender: TObject);
var j,i,sum:byte;
begin
sum:=0;
for i:=1 to T3.RowCount-1 do begin
sum:=sum+strtoint(T3.cells[1,i]); end;
E3.text:=inttostr(sum);
end;
procedure TForm1.Button5Click(Sender: TObject);
var j,i,sum:byte;
begin
sum:=0;
for i:=1 to T2.RowCount-1 do begin
sum:=sum+strtoint(T2.cells[1,i]); end;
E2.text:=inttostr(sum);
end;
procedure TForm1.Button10Click(Sender: TObject);
var i,j,m:byte;max,k:integer;
begin
k:=1;
max:=StrToInt(T1.Cells[1,1]);
for i:=2 to T1.RowCount-2 do
if StrToInt(T1.Cells[1,i])>max then begin max:=StrToInt(T1.Cells[1,i]);k:=i;
end;
T4.Cells[1,1]:=IntToStr(max);
T4.Cells[0,1]:=T1.Cells[0,k];
inc(k);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button13Click(Sender: TObject);
var i,j,m:byte;max,k:integer;
begin
k:=1;
max:=StrToInt(T2.Cells[1,1]);
for i:=2 to T2.RowCount-2 do
if StrToInt(T2.Cells[1,i])>max then begin max:=StrToInt(T2.Cells[1,i]);k:=i;
end;
T4.Cells[1,2]:=IntToStr(max);
T4.Cells[0,2]:=T2.Cells[0,k];
inc(k);
end;
procedure TForm1.Button14Click(Sender: TObject);
var i,j,m:byte;max,k:integer;
begin
k:=1;
max:=StrToInt(T3.Cells[1,1]);
for i:=2 to T3.RowCount-1 do
if StrToInt(T3.Cells[1,i])>max then begin max:=StrToInt(T3.Cells[1,i]);k:=i;
end;
T4.Cells[1,3]:=IntToStr(max);
T4.Cells[0,3]:=T3.Cells[0,k];
inc(k);
end;
end.
procedure TForm1.Button5Click(Sender: TObject);
begin
end;
procedure TForm1.Button5Click(Sender: TObject);
var j,i,sum:byte;
begin
sum:=0;
for i:=1 to T2.RowCount-1 do begin
sum:=sum+strtoint(T2.cells[1,i]); end;
E2.text:=inttostr(sum);
end;
procedure TForm1.Button9Click(Sender: TObject);
var j,i,sum:byte;
begin
sum:=0;
for i:=1 to T3.RowCount-1 do begin
sum:=sum+strtoint(T3.cells[1,i]); end;
E3.text:=inttostr(sum);
end;
end.