implementation
{$R *.DFM}
procedure TForm1.NextQuestion;
var
i : integer;
begin
if (FiCountCorrect = 10)
or (FiCountTries=3)
then //15
begin
ShowResults;
exit;
end;
FiCountQuestion:=Random(6)+1;
//inc(FiCountQuestion);
Label6.Caption:=IntToStr(FiCountCorrect);
FiCountTries := 2;
GroupBox2.Caption := IntToStr(FiCountQuestion)+'
. Frage';
Label2.Caption := aqQuiz[FiCountQuestion].sQuestion;
Edit2.text := IntToStr(FiCountTries);
for i := 1
to 4
do
begin
TButton(FindComponent('
Button'+IntToStr(i))).Caption := chr(64+i)+'
- '+aqQuiz[FiCountQuestion].sAnswer[i];
end;
FICorrect := aqQuiz[FiCountQuestion].iCorrect;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
j : integer;
sSection :
string;
begin
Randomize;
iniQuiz := TIniFile.Create(ExtractFilePath(paramstr(0))+'
Quiz.ini');
try
for i := 1
to 6
do //15
begin
sSection := '
Frage'+IntToStr(i);
aqQuiz[i].sQuestion := iniQuiz.ReadString(sSection,'
Frage','
');
for j := 1
to 4
do
begin
aqQuiz[i].sAnswer[j] := iniQuiz.ReadString(sSection,'
Antwort'+IntToStr(j),'
');
end;
aqQuiz[i].iCorrect := iniQuiz.ReadInteger(sSection,'
Korrekt',0);
end;
FiCountCorrect := 0;
FiCountError := 0;
FiCountQuestion := 0;
NextQuestion;
finally
FreeAndNil(iniQuiz);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
iChoice : integer;
begin
iChoice := 1;
if iChoice = FiCorrect
then
begin
//ShowMessage('Richtig');
inc(FiCountCorrect);
NextQuestion;
exit;
end;
if FiCountTries = 2
then
begin
ShowMessage('
Leider falsch.'#13#10'
Noch ein Versuch.');
dec(FiCountTries);
Edit2.Text := IntToStr(FiCountTries);
exit;
end;
ShowMessage('
Leider falsch.');
inc(FiCountError);
FiCountTries:=3;
NextQuestion;
end;
.....
procedure TForm1.ShowResults;
begin
ShowMessage('
Das Quiz ist vorbei.'#13#10'
Richtig: '+IntToStr(FiCountCorrect)+#13#10'
Falsch: '+IntToStr(FiCountError));
if Application.MessageBox('
Neues Spiel anfangen?','
Frage',36) = 7
then Close;
FormCreate(Sender);
//HIER KOMMT DER FEHLER
end;