1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label3: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n:integer;
mas_name:array[1..20] of String;
mas_yearofbirth:array[1..20] of Integer;
mas_position:array[1..20] of String;
mas_pay_envelope:array[1..20] of Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
type
TLab=record
name:String[10];
yearofbirth:integer;
position:String[10];
pay_envelope:integer;
end;
var
j:integer;
MyFile:File of TLab;
Lab:TLab;
begin
//Формирование шапки таблицы
StringGrid1.Cells[0,0]:='№';
StringGrid1.Cells[1,0]:='Фамилия';
StringGrid1.Cells[2,0]:='Год рождения';
StringGrid1.Cells[3,0]:='Должность';
StringGrid1.Cells[4,0]:='Зарплата';
AssignFile(MyFile,'stud.dat');
Rewrite(MyFile);
//==Формирование таблицы в типизированном файле
Lab.name:='Guffanov';
Lab.yearofbirth:=1980;
Lab.position:='Spe******t';
Lab.pay_envelope:=4000;
Seek(MyFile,0);
Write(MyFile,Lab);
Lab.name:='G-rypguHoB';
Lab.yearofbirth:=1981;
Lab.position:='Spe******t';
Lab.pay_envelope:=4100;
Seek(MyFile,1);
Write(MyFile,Lab);
Lab.name:='Yazev';
Lab.yearofbirth:=1985;
Lab.position:='Spe******t';
Lab.pay_envelope:=3900;
Seek(MyFile,2);
Write(MyFile,Lab);
Lab.name:='Chumacheckii';
Lab.yearofbirth:=1993;
Lab.position:='Student';
Lab.pay_envelope:=1200;
Seek(MyFile,3);
Write(MyFile,Lab);
Lab.name:='Labalala';
Lab.yearofbirth:=1992;
Lab.position:='Student';
Lab.pay_envelope:=1200;
Seek(MyFile,4);
Write(MyFile,Lab);
Lab.name:='Nesterov';
Lab.yearofbirth:=1994;
Lab.position:='Student';
Lab.pay_envelope:=1100;
Seek(MyFile,5);
Write(MyFile,Lab);
//=======================================
n:=FileSize(MyFile); // Сохраним количество записей в файле
for j:=1 to n do
begin
//Считываем переменные из файла
Seek(MyFile,j-1);
read(MyFile,Lab);
mas_name[j]:=Lab.name;
mas_yearofbirth[j]:=Lab.yearofbirth;
mas_position[j]:=Lab.position;
mas_pay_envelope[j]:=Lab.pay_envelope;
end;
CloseFile(MyFile);
//Вывод данных из файла на форму
for j:=1 to n do
begin
StringGrid1.Cells[0,j]:=IntToStr(j);
StringGrid1.Cells[1,j]:=mas_name[j];
StringGrid1.Cells[2,j]:=IntToStr(mas_yearofbirth[j]);
StringGrid1.Cells[3,j]:=mas_position[j];
StringGrid1.Cells[4,j]:=IntToStr(mas_pay_envelope[j]);
end;
//Формирование шапки таблицы для компонента ST2
StringGrid2.Cells[0,0]:='№';
StringGrid2.Cells[1,0]:='Фамилия';
StringGrid2.Cells[2,0]:='Год';
StringGrid2.Cells[3,0]:='Должность';
StringGrid2.Cells[4,0]:='Зарплата';
end;
//Процедура обработки кнопки "Результат".
procedure TForm1.Button1Click(Sender: TObject);
var
j:integer;
i:integer;
begin
i:=0;
for j:=1 to n do //Перебираем строки таблицы
begin
inc(i);// Увеличиваем индекса массива
StringGrid2.Cells[1,i]:=mas_name[j];
StringGrid2.Cells[2,i]:=IntToStr(mas_yearofbirth[j]);
StringGrid2.Cells[3,i]:=mas_position[j];
StringGrid2.Cells[4,i]:=IntToStr(mas_pay_envelope[j]);
end;
end;
//Процедура обработки кнопки "Выход"
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
end;
end. |