Лабораторная работа № 3.
Неоднородные структуры данных.
Тип запись в языках программирования.
Работа с записями в языке Object Pascal в Delphi
1. Цель работы:
Целью лабораторной работы является изучение алгоритмов работы с
записями в языке Object Pascal.
Ход Работы:
Используемые компоненты в данной работе:
· TCheckBox– (закладка Standart) – переключатель с двумя состояниями.
· TRadioGroup –(закладка Standart) –группа переключателей, позволяющих выбрать одно из нескольких состояний.
· TListBox –(закладка Standart) окно выбора, используется для выбора текстового пункта.
· TComboBox– (закладка Standart) ниспадающее окно выбора, используется для выбора текстового пункта.
· TTimer– (закладка System) – таймер.
· TProgressBar –(закладка System) –полоса графического отображения состояния некоторого процесса.
· TLabel –Компонент представляет собой статический текст.
· TButton– Обычная кнопка Windows.
Код программы:
Скриншот формы:

Код программы:
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.ExtCtrls,
Vcl.ComCtrls;
type
TForm3 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
ProgressBar1: TProgressBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Timer1: TTimer;
RadioGroup1: TRadioGroup;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ListBox1: TListBox;
StringGrid1: TStringGrid;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TStudent=record
ima:string; god:integer;age:integer; gruppa:string;
end;
TGroup=array [0..35] of TStudent;
Var grp: TGroup; num,n,i:integer;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
with Grp[Num] do
begin
ima:=StringGrid1.Cells[1,0];
age:=StrToInt(StringGrid1.Cells[1,1]);
gruppa:=StringGrid1.Cells[1,2];
god:=StrToInt(StringGrid1.Cells[1,3]);
end;
ListBox1.Items.Add(Grp[Num].Ima);
ListBox1.ItemIndex:=ListBox1.Items.Count-1;
ComboBox1.Items.Add('Запись '+inttostr(num));
ComboBox1.ItemIndex:=ListBox1.Items.Count-1;
inc(Num);
Label4.Caption:='Всего: '+IntToStr(Num);
Label3.Caption:=Grp[listbox1.itemindex].Ima;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
if Application.MessageBox('Удалить запись?','Удаление записи',0)=0 then exit;
n:=ListBox1.ItemIndex;
if n>=0 then
begin
for i:=n to Num-2 do
Grp[i]:=Grp[i+1];
ListBox1.Items.Delete(n);
ComboBox1.Items.Delete(n);
dec(Num);
Label4.Caption:='Всего: '+IntToStr(Num);
ListBox1.ItemIndex:=-1;
end;
end;
procedure TForm3.Button3Click(Sender: TObject);
begin
n:=ListBox1.ItemIndex;
with Grp[n] do
begin
ima:=StringGrid1.Cells[1,0];
age:=StrToInt(StringGrid1.Cells[1,1]);
gruppa:=StringGrid1.Cells[1,2];
god:=strtoint(StringGrid1.Cells[1,3]);
end;
listbox1.Items.Insert(n,Grp[n].ima);
listbox1.Items.delete(n+1);
end;
procedure TForm3.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked=false then begin
timer1.Enabled:=false;
button1.Enabled:=true;
button2.Enabled:=true;
button3.Enabled:=true;
listbox1.Enabled:=true;
combobox1.Enabled:=true;
ProgressBar1.position:=0;
end
else
if listbox1.Items.count<>0 then begin
button1.Enabled:=false;
button2.Enabled:=false;
button3.Enabled:=false;
listbox1.Enabled:=false;
combobox1.Enabled:=false;
listbox1.ItemIndex:=0;
timer1.Enabled:=true;
end;
end;
procedure TForm3.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked=true then ProgressBar1.Visible:=true
else ProgressBar1.Visible:=false;
end;
procedure TForm3.ComboBox1Change(Sender: TObject);
begin
listbox1.itemIndex:=combobox1.ItemIndex;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='Фамилия, инициалы';
StringGrid1.Cells[0,1]:='Возраст';
StringGrid1.Cells[0,2]:='Группа';
StringGrid1.Cells[0,3]:='Курс';
timer1.enabled:=false;
CheckBox2.Checked:=true;
end;
procedure TForm3.ListBox1Click(Sender: TObject);
begin
n:=ListBox1.ItemIndex;
if n>=0 then
begin
StringGrid1.Cells[1,0]:=Grp[n].Ima;
StringGrid1.Cells[1,1]:=inttostr(Grp[n].age);
StringGrid1.Cells[1,2]:=Grp[n].gruppa;
StringGrid1.Cells[1,3]:=inttostr(Grp[n].god);
end;
combobox1.itemindex:=listbox1.itemindex;
label3.caption:=Grp[listbox1.itemindex].Ima;
end;
procedure TForm3.RadioButton1Click(Sender: TObject);
begin
label2.caption:='Курс: '+inttostr(Grp[n].god);
end;
procedure TForm3.RadioButton2Click(Sender: TObject);
begin
label2.caption:='Группа: '+Grp[n].gruppa;
end;
procedure TForm3.RadioButton3Click(Sender: TObject);
begin
label2.caption:='Возраст: '+IntToStr(Grp[n].age);
end;
procedure TForm3.Timer1Timer(Sender: TObject);
begin
if Progressbar1.position=100 then begin
listbox1.itemindex:=-1;
progressbar1.Position:=0;
end;
ProgressBar1.Position:=ProgressBar1.Position+(100 div listbox1.Items.count);
listbox1.ItemIndex:=listbox1.itemindex+1;
label3.caption:=Grp[listbox1.itemindex].Ima;
end;
end.
Скриншот готовой программы:

Вывод: В ходе данной лабораторной работы я изучил алгоритмы работы с
записями в языке Object Pascal.