How to make the questions displayed randomly in the order in Delphi 7?

Good day!

Please help with the code. There is code for testing is written in Delphi 7.
The program is working, but all the questions are displayed in order. I have to questions displayed randomly.

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ExtCtrls, jpeg;

type
 TForm1 = class(TForm)
 Button1: TButton;
 AnswerGroup: TRadioGroup;
 GroupBox1: TGroupBox;
 Question: TLabel;
 TestBox: User Would Like;
 Button2: TButton;
 procedure Button1Click(Sender: TObject);
 procedure LoadQuestion(Index: integer);
 procedure FormCreate(Sender: TObject);
 procedure LoadTest(Index: integer);
 TestBoxCloseUp procedure(Sender: TObject);
 procedure Button2Click(Sender: TObject);
private
public
end;

const
 TestName='Test_'; // name of test file
 max=1000; // maximum number of questions
var
 Form1: TForm1;
 QuestionText: array [0..max] of string; // question text
 AnswerQuestion: array [0..max] of byte; // correct answer
 QuestionText1: array [0..max] of string;// first question
 QuestionText2: array [0..max] of string;// second question
 QuestionText3: array [0..max] of string;// third question
 Ball: integer=0; // score
 now: integer:=0;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 if AnswerQuestion[now]=AnswerGroup.ItemIndex+1 then // compare the response value and the selected value
inc(ball);
 AnswerGroup.ItemIndex:=-1; // remove vydelenie with group answers
 inc(now); // increase the question 1
 LoadQuestion(now); // load it
end;

procedure TForm1.LoadQuestion(Index: integer);
begin
 if QuestionText[Index]<>" then// if the selected question there is that will ship it
begin
 AnswerGroup.Items.Clear;// clear field responses
 Question.Caption:=QuestionText[Index];// set the request
 AnswerGroup.Items.Add(QuestionText1[index]);// add response
 AnswerGroup.Items.Add(QuestionText2[index]); // add response
 AnswerGroup.Items.Add(QuestionText3[index]); // add response
end
 else // otherwise, inform that the test is completed
begin
 showmessage('Test completed'+#13+'Correct answers: '+inttostr(ball)); // message that the test is over and give the number of correct answers
 button1.Enabled:=false; // make inactive button
 button2.Enabled:=true; // include reference
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
 s: Tstrings;
 i: Integer;
begin
i:=0;
 while FileExists(ExtractFilePath(application.ExeName)+TestName+inttostr(i)+'.txt') do // check the test files
begin
 application.ProcessMessages; // that b is not inhibited
 s:=tstringlist.Create; // create a variable
 s.LoadFromFile(ExtractFilePath(application.ExeName)+TestName+inttostr(i)+'.txt'); // downloadable file
 if s.Text<>" then // if not empty then
 TestBox.Items.Add(s.Strings[0]); // add the group of tests called test
 s.Free; // destroy variable
 inc(i); // increment counter
end;
end;

procedure TForm1.LoadTest(Index: integer);
var
 s: Tstrings;
 j, h: Integer;
begin
h:=0;
 s:=tstringlist.Create; // create a variable
 s.LoadFromFile(ExtractFilePath(application.ExeName)+TestName+inttostr(Index)+'.txt'); // loaded
 if s.Text<>" then // if not empty then
begin
 form1.Caption:=s.Strings[0]; // name of test
 for j := 1 to s.Count - 1 do // start to assign values
begin
 if s.Strings[j]='__________' then // this is the separator we are looking for
begin
 QuestionText[h]:=s.Strings[j+1]; // question text
 QuestionText1[h]:=s.Strings[j+2];// the text of the first answer
 QuestionText2[h]:=s.Strings[j+3];// the text of the second answer
 QuestionText3[h]:=s.Strings[j+4];// text of the third variant of the answer
 AnswerQuestion[h]:=strtoint(s.Strings[j+5]); // the number of the answer
 inc(h); // increment counter for that would write to a new array element

end
end;
end;
 s.Free; // destroy variable
 LoadQuestion(now);// loaded question here it always = 0
end;

procedure TForm1.TestBoxCloseUp(Sender: TObject);
begin
ball:=0;
now:=0;
button1.Enabled:=true;
button2.Enabled:=false;
LoadTest(TestBox.ItemIndex);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.ShowModal;
end;

end.
June 10th 19 at 16:30
1 answer
June 10th 19 at 16:32
Oddly enough - you need to use the Random function.
What exactly does not work? - nikita.Stracke commented on June 10th 19 at 16:35

Find more questions by tags Delphi