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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ExtCtrls, sSkinProvider, sSkinManager;
type
// Годинниковий тип
TPrTime = Record
Min: Byte;
Sec: Byte;
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N11: TMenuItem;
Panel1: TPanel;
Lbl_Last: TLabel;
Lbl_FQuestion: TLabel;
BtnV1: TButton;
BtnV2: TButton;
BtnV3: TButton;
BtnV4: TButton;
MQuestion: TMemo;
MIAbout: TMenuItem;
Timer1: TTimer;
MITest: TMenuItem;
MITBegin: TMenuItem;
MIOpenFile: TMenuItem;
Memo_Temp: TMemo;
MV1: TMemo;
MV2: TMemo;
MV3: TMemo;
MV4: TMemo;
OpenDialog1: TOpenDialog;
GBox: TGroupBox;
MIExit: TMenuItem;
MITEnd: TMenuItem;
LblNameTest: TLabel;
Label1: TLabel;
Label2: TLabel;
PanelButton: TPanel;
Label3: TLabel;
Lbl_NomQuestion: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Memo_txt: TMemo;
N1: TMenuItem;
Panel2: TPanel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
sSkinManager1: TsSkinManager;
sSkinProvider1: TsSkinProvider;
procedure FormCreate(Sender: TObject);
function DecTime(Var aa:TPrTime; Sender: TObject): string;
procedure PrTimeOut(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure MIOpenFileClick(Sender: TObject);
procedure MIAboutClick(Sender: TObject);
procedure PrFillFileds(Sender: TObject);
procedure MITBeginClick(Sender: TObject);
procedure PrClickButton(Sender: TObject);
procedure MIExitClick(Sender: TObject);
procedure N1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
fileName: string;
MyTextF: TextFile;
//HelpFile:Textfile;
PrTimeLast: TPrTime;
PrTimeFull: TPrTime;
// поряд. номер питання
NomQuestion: Byte;
// к-сть прав. відповідей
PrVAnsverOK: Byte;
// набраний бал
Bal:real;
// Масив, в якому зберігаються номера питань ---
PrOrderQuestion: array [1..255] of byte;
implementation
uses OKCANCL2, shellapi;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
GBox.Visible:=False;
Timer1.Enabled:=False;
PrTimeLast.Min:=0;
PrTimeLast.Sec:=0;
MITBegin.Enabled:=True;
MITEnd.Enabled:=False;
NomQuestion:=1;
Memo_Temp.Lines.Clear;
PrVAnsverOK:=0;
PanelButton.Visible:=True;
end;
// Форматування часу ---
Function PrFormatConvert(aa:TPrTime): String;
begin
if aa.Min<=9 then result:='0'+IntToStr(aa.Min)
else result:=IntToStr(aa.Min);
if aa.Sec<=9 then result:=result+':0'+IntToStr(aa.Sec)
else result:=result+':'+IntToStr(aa.Sec);
end;
// Зміна часу.
function TForm1.DecTime(Var aa:TPrTime; Sender: TObject): string;
begin
if aa.Sec=0 then
if aa.Min>0 then
begin
dec(aa.Min);
aa.Sec:=59;
end
else PrTimeOut(Sender)
else dec(aa.Sec);
result:=PrFormatConvert(aa);
end;
// Дія при закінченні часу чи дострокового завершення
procedure TForm1.PrTimeOut(Sender: TObject);
begin
// Виведення статистики закінчення тесту
if NomQuestion=StrToInt(copy(Memo_Temp.Lines[1],1,pos(' ',Memo_Temp.Lines[1])-1)) then
begin
Timer1.Enabled:=False;
PanelButton.Visible:=False; // Відключення кнопок відповідей
ShowMessage('Відповідей (загальна к-сть\вірних):'+#13+#10
+IntToStr(NomQuestion)+'\'+IntToStr(PrVAnsverOK)); //PrStatisticsTest(Sender);
// статистика в едіти
edit1.Text:= IntToStr(PrVAnsverOK);
edit2.Text:= IntToStr(NomQuestion-PrVAnsverOK);
edit3.Text:= IntToStr(NomQuestion);
// початок оцінювання за шкалою
Bal:= (PrVAnsverOK/NomQuestion*100);
if Bal=0 then label7.Caption:='Ви не набрали жодного балу!' else
if (Bal>0) and (Bal<20) then label7.Caption:='Ваша оцінка 1' else
if (Bal>=20) and (Bal<=29) then label7.Caption:='Ваша оцінка 2' else
if (Bal>=30) and (Bal<=44) then label7.Caption:='Ваша оцінка 3' else
if (Bal>=45) and (Bal<=54) then label7.Caption:='Ваша оцінка 4' else
if (Bal>=55) and (Bal<=64) then label7.Caption:='Ваша оцінка 5' else
if (Bal>=65) and (Bal<=74) then label7.Caption:='Ваша оцінка 6' else
if (Bal>=75) and (Bal<=79) then label7.Caption:='Ваша оцінка 7' else
if (Bal>=80) and (Bal<=84) then label7.Caption:='Ваша оцінка 8' else
if (Bal>=85) and (Bal<=94) then label7.Caption:='Ваша оцінка 9' else
if (Bal>=95) and (Bal<=99) then label7.Caption:='Ваша оцінка 10' else
label7.Caption:='Ваша оцінка 11';
Label8.Caption:=(name1)+' '+(surname);
Memo_txt.Text:=Label8.Caption+' | '+Label7.Caption+' | '+klas+' клас'+' | '+'тест '+Memo_Temp.Lines[0];
// Memo_txt.Lines.SaveToFile('Results.txt'); збереження поверху
// --- Збереження в файл
//AssignFile(MyTextF, 'Results.txt');
//Append (MyTextF); //ругается вот сюда "Exception class EInOutError with message 'File not found'"
//WriteLn(MyTextF, Memo_txt.Text);
//Flush (MyTextF);
// CloseFile(MyTextF);
// друга спроба
begin
// Попытка открыть текстовый файл для записи
fileName := 'Results.txt';
AssignFile(MyTextF, fileName);
Append (MyTextF); // все равно также ругается и сюда
// Запись в файл
WriteLn(MyTextF, Memo_txt.Text);
// Закрытие файла
CloseFile(MyTextF);
end;
if FileExists(fileName)
then ShowMessage(fileName+' существует')
else ShowMessage(fileName+' не существует');
Abort;
end;
// --- Відновлення часу на питання ---
{v0103} PrTimeLast.Min:=StrToInt(copy(Memo_Temp.Lines[1],pos(' ',Memo_Temp.Lines[1])+1,pos(':',Memo_Temp.Lines[1])-pos(' ',Memo_Temp.Lines[1])-1));
{v0103} PrTimeLast.Sec:=StrToInt(copy(Memo_Temp.Lines[1],pos(':',Memo_Temp.Lines[1])+1,Length(Memo_Temp.Lines[1])-pos(':',Memo_Temp.Lines[1])));
// Збільшення номеру запитання на 1
inc(NomQuestion);
PrFillFileds(Sender);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// --- Зменшити час на відповідь на 1 сек ---
Lbl_Last.Caption:=DecTime(PrTimeLast,Sender);
end;
// Відкриття файлу
procedure TForm1.MIOpenFileClick(Sender: TObject);
begin
FormCreate(Sender);
OpenDialog1.InitialDir:=ExtractFilePath(Application.ExeName);
if OpenDialog1.Execute then
begin
Memo_Temp.Lines.LoadFromFile(OpenDialog1.FileName);
// відкриття діалогового вікн для введення даних
OKRightDlg.ShowModal;
// інструкція щодо початку тестування
Label13.Caption:='';
label10.Caption:='Завантажено тест '+'"'+Memo_Temp.Lines[0]+'".'+' '+#13+#10+#13+#10+'Всього запитань - '+ Memo_Temp.Lines[1];//,1,pos(' ',Memo_Temp.Lines[1])-1;
//Memo_Temp.Lines[1];
label11.Caption:='Для початку тестування перейдіть в меню "Тест - Розпочати тестування!"';
Label12.Caption:='Бажаю успіху!';
end;
end;
procedure TForm1.MIAboutClick(Sender: TObject);
begin
ShowMessage('Програма для тестування знань "Школа-Test v.3.1'+#13+#10+#13+#10+
'Розробник: Лисенко Олександр;'+#13+#10+
' '+#13+#10+
'http:\\[url]www.testonline.at.ua'+#13+#10+#13+#10+[/url]
'e-mail: [email]lysenko.oleksandr@gmail.com[/email]');
end;
// Заповнення полів тесту
procedure TForm1.PrFillFileds(Sender: TObject);
begin
// Очистка поля тесту
label7.Caption:='';
MQuestion.Clear;
MV1.Clear;
MV2.Clear;
MV3.Clear;
MV4.Clear;
MQuestion.Lines[0]:=Memo_Temp.Lines[2+6*(PrOrderQuestion[NomQuestion]-1)];
MV1.Lines[0]:=Memo_Temp.Lines[3+6*(PrOrderQuestion[NomQuestion]-1)];
MV2.Lines[0]:=Memo_Temp.Lines[4+6*(PrOrderQuestion[NomQuestion]-1)];
MV3.Lines[0]:=Memo_Temp.Lines[5+6*(PrOrderQuestion[NomQuestion]-1)];
MV4.Lines[0]:=Memo_Temp.Lines[6+6*(PrOrderQuestion[NomQuestion]-1)];
Lbl_NomQuestion.Caption:=IntToStr(NomQuestion);
// Управління полосою прокрутки в полях тексту
if MQuestion.Lines.Count>=3 then MQuestion.scrollbars:=ssVertical else MQuestion.scrollbars:=ssNone;
if MV1.Lines.Count>=3 then MV1.scrollbars:=ssVertical else MV1.scrollbars:=ssNone;
if MV2.Lines.Count>=3 then MV2.scrollbars:=ssVertical else MV2.scrollbars:=ssNone;
if MV3.Lines.Count>=3 then MV3.scrollbars:=ssVertical else MV3.scrollbars:=ssNone;
if MV4.Lines.Count>=3 then MV4.scrollbars:=ssVertical else MV4.scrollbars:=ssNone;
end;
// Пункт із меню "Розпочати тестування"
procedure TForm1.MITBeginClick(Sender: TObject);
Var
Stroka: String;
tempNomQuestion, i: byte;
begin
Panel2.Visible:=False;
label15.Caption:=Memo_Temp.Lines[7];
// Перевірка чи був відкритий файл з тестом
if Memo_Temp.Lines.Count<4 then
begin
ShowMessage('Відкрийте файл тесту!');
Abort;
end;
// Розрахунок часу на 1 питання і на всі.
Stroka:=Memo_Temp.Lines[1];
PrTimeLast.Min:=StrToInt(copy(Stroka,pos(' ',Stroka)+1,pos(':',Stroka)-pos(' ',Stroka)-1));
PrTimeLast.Sec:=StrToInt(copy(Stroka,pos(':',Stroka)+1,Length(Stroka)-pos(':',Stroka)));
PrTimeFull.Sec:=StrToInt(copy(Stroka,1,pos(' ',Stroka)-1))
*PrTimeLast.Sec mod 60;
PrTimeFull.Min:=StrToInt(copy(Stroka,1,pos(' ',Stroka)-1))
*PrTimeLast.Min + StrToInt(copy(Stroka,1,pos(' ',Stroka)-1))
*PrTimeLast.Sec div 60;
// Очищення випадкового порядку питань ---
for i:=1 to 255 do
PrOrderQuestion[i]:=0;
tempNomQuestion:=0;
// --- вибір питаннь у випадковому порядку ---
while tempNomQuestion<StrToInt(copy(Memo_Temp.Lines[1],1,pos(' ',Memo_Temp.Lines[1])-1)) do
begin
randomize;
i:=1+random(StrToInt(copy(Memo_Temp.Lines[1],1,pos(' ',Memo_Temp.Lines[1])-1)));
if PrOrderQuestion[i]=0 then
begin
inc(tempNomQuestion);
PrOrderQuestion[i]:=tempNomQuestion;
end;
end;
PrFillFileds(Sender);
// Заповнення полів форми
LblNameTest.Caption:=Memo_Temp.Lines[0];
Lbl_FQuestion.Caption:=PrFormatConvert(PrTimeFull);
Lbl_Last.Caption:=PrFormatConvert(PrTimeLast);
NomQuestion:=1;
MITBegin.Enabled:=False;
MITEnd.Enabled:=True;
GBox.Visible:=True;
PanelButton.Visible:=True;
Timer1.Enabled:=True;
end;
// меню Допомога
procedure TForm1.N1Click(Sender: TObject);
begin
ShellExecute(Application.Handle,'open','Test_Help.hlp',nil,nil,0);
//Application.HelpFile := 'Test.chm'; /////////// hеlp файл
end;
// Натиснення на кнопку з варіантом відповіді
procedure TForm1.PrClickButton(Sender: TObject);
begin
if StrToInt(Memo_Temp.Lines[7+6*(NomQuestion-1)])=(Sender as TButton).Tag Then
begin
ShowMessage('Вірно!');
inc(PrVAnsverOK);
end
else ShowMessage('Невірно!');
PrTimeOut(Sender);
end;
procedure TForm1.MIExitClick(Sender: TObject);
begin
Close;
end;
end. |