Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit uMain;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
- type
- TfMain = class(TForm)
- cQuestionNumber: TPanel;
- cQuestionText: TPanel;
- cAncwerPanel1: TPanel;
- Panel1: TPanel;
- cNextButton: TButton;
- cAnswer1: TRadioButton;
- cAnswer2: TRadioButton;
- cAnswer3: TRadioButton;
- cAnswer4: TRadioButton;
- procedure FormCreate(Sender: TObject);
- procedure cNextButtonClick(Sender: TObject);
- private
- procedure SetQuestion(Number: integer);
- procedure cAnswerClick(Sender: TObject);
- end;
- var
- fMain: TfMain;
- implementation
- {$R *.dfm}
- type
- TQuestion = packed record
- Question: string;
- Answer1 : string;
- Answer2 : string;
- Answer3 : string;
- Answer4 : string;
- Valid : Integer;
- end;
- var
- Current : Integer;
- ResultValid: Integer;
- Questions : array of TQuestion;
- procedure TfMain.FormCreate(Sender: TObject);
- var
- i : integer;
- QFile: TStringList;
- begin
- cAnswer1.OnClick := cAnswerClick;
- cAnswer2.OnClick := cAnswerClick;
- cAnswer3.OnClick := cAnswerClick;
- cAnswer4.OnClick := cAnswerClick;
- SetLength(Questions, 0);
- QFile := TStringList.Create;
- QFile.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Questions.txt');
- i := 0;
- repeat
- SetLength(Questions, Length(Questions) + 1);
- with Questions[High(Questions)] do
- begin
- Question := QFile.Strings[i];
- Answer1 := QFile.Strings[i + 1];
- Answer2 := QFile.Strings[i + 2];
- Answer3 := QFile.Strings[i + 3];
- Answer4 := QFile.Strings[i + 4];
- Valid := StrToIntDef(QFile.Strings[i + 5], 1);
- end;
- Inc(i, 6);
- until i >= Pred(QFile.Count);
- Current := 0;
- ResultValid := 0;
- SetQuestion(Current);
- end;
- procedure TfMain.cNextButtonClick(Sender: TObject);
- begin
- case Questions[Current].Valid of
- 1: if cAnswer1.Checked then Inc(ResultValid);
- 2: if cAnswer2.Checked then Inc(ResultValid);
- 3: if cAnswer3.Checked then Inc(ResultValid);
- 4: if cAnswer4.Checked then Inc(ResultValid);
- end;
- if Current <> High(Questions) then
- begin
- Inc(Current);
- SetQuestion(Current);
- end else begin
- MessageBoxA(Handle, LPCSTR('Верных ' + IntToStr(ResultValid) + ' из ' + IntToStr(Length(Questions))),
- 'Результаты', MB_ICONINFORMATION or MB_OK);
- ExitProcess(0);
- end;
- end;
- procedure TfMain.SetQuestion(Number: integer);
- begin
- cQuestionNumber.Caption := 'Вопрос №' + IntToStr(Number + 1);
- cQuestionText.Caption := Questions[Number].Question;
- cAnswer1.Caption := Questions[Number].Answer1;
- cAnswer2.Caption := Questions[Number].Answer2;
- cAnswer3.Caption := Questions[Number].Answer3;
- cAnswer4.Caption := Questions[Number].Answer4;
- cAnswer1.Checked := False;
- cAnswer2.Checked := False;
- cAnswer3.Checked := False;
- cAnswer4.Checked := False;
- cAnswer1.Enabled := (Trim(cAnswer1.Caption) <> '');
- cAnswer2.Enabled := (Trim(cAnswer2.Caption) <> '');
- cAnswer3.Enabled := (Trim(cAnswer3.Caption) <> '');
- cAnswer4.Enabled := (Trim(cAnswer4.Caption) <> '');
- cNextButton.Enabled := False;
- end;
- procedure TfMain.cAnswerClick(Sender: TObject);
- begin
- cNextButton.Enabled := True;
- end;
- end.
Add Comment
Please, Sign In to add comment