HEX0x29A

Пример теста

Oct 28th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.38 KB | None | 0 0
  1. unit uMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TfMain = class(TForm)
  11.     cQuestionNumber: TPanel;
  12.     cQuestionText: TPanel;
  13.     cAncwerPanel1: TPanel;
  14.     Panel1: TPanel;
  15.     cNextButton: TButton;
  16.     cAnswer1: TRadioButton;
  17.     cAnswer2: TRadioButton;
  18.     cAnswer3: TRadioButton;
  19.     cAnswer4: TRadioButton;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure cNextButtonClick(Sender: TObject);
  22.   private
  23.     procedure SetQuestion(Number: integer);
  24.     procedure cAnswerClick(Sender: TObject);
  25.   end;
  26.  
  27. var
  28.   fMain: TfMain;
  29.  
  30. implementation
  31.  
  32. {$R *.dfm}
  33.  
  34. type
  35.   TQuestion = packed record
  36.     Question: string;
  37.     Answer1 : string;
  38.     Answer2 : string;
  39.     Answer3 : string;
  40.     Answer4 : string;
  41.     Valid   : Integer;
  42.   end;
  43.  
  44. var
  45.   Current    : Integer;
  46.   ResultValid: Integer;
  47.   Questions  : array of TQuestion;
  48.  
  49. procedure TfMain.FormCreate(Sender: TObject);
  50. var
  51.   i    : integer;
  52.   QFile: TStringList;
  53. begin
  54.   cAnswer1.OnClick := cAnswerClick;
  55.   cAnswer2.OnClick := cAnswerClick;
  56.   cAnswer3.OnClick := cAnswerClick;
  57.   cAnswer4.OnClick := cAnswerClick;
  58.   SetLength(Questions, 0);
  59.   QFile := TStringList.Create;
  60.   QFile.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Questions.txt');
  61.   i := 0;
  62.   repeat
  63.     SetLength(Questions, Length(Questions) + 1);
  64.     with Questions[High(Questions)] do
  65.     begin
  66.       Question := QFile.Strings[i];
  67.       Answer1  := QFile.Strings[i + 1];
  68.       Answer2  := QFile.Strings[i + 2];
  69.       Answer3  := QFile.Strings[i + 3];
  70.       Answer4  := QFile.Strings[i + 4];
  71.       Valid    := StrToIntDef(QFile.Strings[i + 5], 1);
  72.     end;
  73.     Inc(i, 6);
  74.   until i >= Pred(QFile.Count);
  75.   Current     := 0;
  76.   ResultValid := 0;
  77.   SetQuestion(Current);
  78. end;
  79.  
  80. procedure TfMain.cNextButtonClick(Sender: TObject);
  81. begin
  82.   case Questions[Current].Valid of
  83.     1: if cAnswer1.Checked then Inc(ResultValid);
  84.     2: if cAnswer2.Checked then Inc(ResultValid);
  85.     3: if cAnswer3.Checked then Inc(ResultValid);
  86.     4: if cAnswer4.Checked then Inc(ResultValid);
  87.   end;
  88.   if Current <> High(Questions) then
  89.   begin
  90.     Inc(Current);
  91.     SetQuestion(Current);
  92.   end else begin
  93.     MessageBoxA(Handle, LPCSTR('Верных ' + IntToStr(ResultValid) + ' из ' + IntToStr(Length(Questions))),
  94.                 'Результаты', MB_ICONINFORMATION or MB_OK);
  95.     ExitProcess(0);
  96.   end;
  97. end;
  98.  
  99. procedure TfMain.SetQuestion(Number: integer);
  100. begin
  101.   cQuestionNumber.Caption := 'Вопрос №' + IntToStr(Number + 1);
  102.   cQuestionText.Caption   := Questions[Number].Question;
  103.   cAnswer1.Caption        := Questions[Number].Answer1;
  104.   cAnswer2.Caption        := Questions[Number].Answer2;
  105.   cAnswer3.Caption        := Questions[Number].Answer3;
  106.   cAnswer4.Caption        := Questions[Number].Answer4;
  107.   cAnswer1.Checked        := False;
  108.   cAnswer2.Checked        := False;
  109.   cAnswer3.Checked        := False;
  110.   cAnswer4.Checked        := False;
  111.   cAnswer1.Enabled        := (Trim(cAnswer1.Caption) <> '');
  112.   cAnswer2.Enabled        := (Trim(cAnswer2.Caption) <> '');
  113.   cAnswer3.Enabled        := (Trim(cAnswer3.Caption) <> '');
  114.   cAnswer4.Enabled        := (Trim(cAnswer4.Caption) <> '');
  115.   cNextButton.Enabled     := False;
  116. end;
  117.  
  118. procedure TfMain.cAnswerClick(Sender: TObject);
  119. begin
  120.   cNextButton.Enabled := True;
  121. end;
  122.  
  123. end.
Add Comment
Please, Sign In to add comment