Не видит txt-файл теста
Добрый день уважаемые.
Возникла проблема с чтением из txt файла.
В чем проблема?Прошу помощи..
Создание файла log идет, а чтение из q.txt нету.
Здесь не находит.файл лежит в каталоге с программой.
[spoiler]
Код:
unit Unit12;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, unit11;
type
TForm12 = class(TForm)
RadioGroup1: TRadioGroup;
GroupBox1: TGroupBox;
BitBtn1: TBitBtn;
Panel1: TPanel;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form12: TForm12;
balls : integer;
q, Log_File : textfile;
five, four, three,
ans1mark, ans2mark, ans3mark, ans4mark : integer;
question, answere1, answere2, answere3,
answere4, tmp_q, result : string;
flag_end, flag_write : boolean;
implementation
uses Unit1, Unit10, Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9;
{$R *.dfm}
procedure Read_next_q();
var
AYear, AMonth, ADay, Hour, Min, Sec, MSec: Word;
Data : string;
begin
if EOF (q) then
begin
flag_end := true;
if balls>=five then
result:='Отлично ('+IntToStr(balls)+' балла(ов))';
if (balls>=four)and(balls<five) then
result:='Хорошо ('+IntToStr(balls)+' балла(ов))';
if (balls>=three)and(balls<four) then
result:='удовлетворительно ('+IntToStr(balls)+' балла(ов))';
if balls<three then
result:='НЕУДОВЛЕТВОРИТЕЛЬНО ('+IntToStr(balls)+' балла(ов))'+#13#10+'Тест НЕ сдан!';
showmessage('Вы сдали тест на '+#13#10+Result);
DecodeDate(Now, AYear, AMonth, ADay);
DecodeTime(Now, Hour, Min, Sec, MSec);
Data:=IntToStr(AYear)+'/'+IntToStr(AMonth)+'/'+IntToStr(ADay)+' '+IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec)+' ';
writeln(Log_File, Data+Result+#13#10+#13#10);
closeFile(Log_File);
Form12.BitBtn1.Enabled:=false;
end
else
begin
Readln(q,tmp_q);
question:=tmp_q+#13#10;
Readln(q,tmp_q);
question:=question+tmp_q+#13#10;
Readln(q,tmp_q);
question:=question+tmp_q+#13#10;
Readln(q,answere1);
Readln(q,ans1mark);
Readln(q,answere2);
Readln(q,ans2mark);
Readln(q,answere3);
Readln(q,ans3mark);
Readln(q,answere4);
Readln(q,ans4mark);
Form12.Label1.Caption:=question;
Form12.RadioGroup1.Items[0]:=answere1;
Form12.RadioGroup1.Items[1]:=answere2;
Form12.RadioGroup1.Items[2]:=answere3;
Form12.RadioGroup1.Items[3]:=answere4;
end;
end;
procedure check_ans();
begin
if (Form12.RadioGroup1.ItemIndex=0)and(flag_end=false) then
balls:=balls+ans1mark;
if (Form12.RadioGroup1.ItemIndex=1)and(flag_end=false) then
balls:=balls+ans2mark;
if (Form12.RadioGroup1.ItemIndex=2)and(flag_end=false) then
balls:=balls+ans3mark;
if (Form12.RadioGroup1.ItemIndex=3)and(flag_end=false) then
balls:=balls+ans4mark;
Form12.RadioGroup1.ItemIndex:=-1;
end;
procedure TForm12.FormCreate(Sender: TObject);
begin
Form12.Left:=Screen.Width+100;
Form12.Top:=Screen.Height+100;
flag_end:=false;
AssignFile(q, 'q.txt');
Reset(q);
Readln(q,five);
Readln(q,four);
Readln(q,three);
Read_next_q;
end;
procedure TForm12.BitBtn1Click(Sender: TObject);
begin
if Form12.RadioGroup1.ItemIndex<>-1 then
begin
check_ans;
Read_next_q;
end
else
showmessage('Выберите один из вариантов'+#13#10+'ответов и нажмите "Далее"!');
end;
procedure TForm12.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;
end;
end.
[/spoiler]
вот здесь log создается.
Код:
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm11 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form11: TForm11;
implementation
uses Unit12;
{$R *.dfm}
procedure TForm11.FormCreate(Sender: TObject);
begin
Form11.Show;
Form11.Left:=trunc(Screen.Width/2-Form11.Width/2);
Form11.Top:=trunc(Screen.Height/2-Form11.Height/2);
end;
procedure TForm11.BitBtn1Click(Sender: TObject);
begin
if Form11.Edit1.Text<>'' then
begin
AssignFile(Log_File,'Log.txt');
if not(FileExists('Log.txt')) then
Rewrite(Log_File)
else
Append(Log_File);
Writeln(Log_File, Form11.Edit1.Text+' ');
Form11.Hide;
Form12.Showmodal;
end
else
ShowMessage('Введите свое имя!');
end;
procedure TForm11.BitBtn2Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm11.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;
end;
end.
Жду с нетерпением отзывов.
вот сама программа ПАРОЛЬ 123
http://www.fayloobmennik.net/2915026
|