kopierreko
Messages postés139Date d'inscriptionmercredi 12 mars 2008StatutMembreDernière intervention10 juillet 2010
-
23 avril 2008 à 14:10
Sat83
Messages postés166Date d'inscriptionmardi 11 novembre 2003StatutMembreDernière intervention13 octobre 2008
-
5 mai 2008 à 17:59
Bonjour tout le monde;
Je dois créer un questionnaire en deplhi, mais par étape: C-A-D
1ère question, je rempli le formulaire, et là, un message apparait me disant si j'ai bon ou si j'ai faux, et en même temps, là fenêtre se quitte et passe à la question d'après.
Comment procéder ?
Merci
procedure TForm1.FormCreate(Sender: TObject);
begin
listQuestion := TStringList.Create; //on creer la liste de questions
listReponse := TStringList.Create; // on creer la liste de reponses
listQuestion.LoadFromFile('templates\chmnd.data'); //on charge depuis le fichier
listReponse.LoadFromFile('templates\drxfm.data'); //on charge depuis le fichier
index := 0;
LblQuestion.caption := listQuestion.strings[index];
cptBonneRep := 0 ;
end;
procedure TForm1.BtnValidClick(Sender: TObject);
var nbrQuestion : integer ;
messageTmp : string ;
begin
if ( uppercase( EdtReponse.Text ) = uppercase( listReponse.strings[index] )) then
begin
Application.MessageBox('FELICITATION, VOUS AVEZ LA BONNE REPONSE!','RESULTAT',MB_ICONINFORMATION + MB_OK) ;
cptBonneRep := cptBonneRep + 1 ; // on compte les bonnes reponses
end else
begin
messageTmp := 'DOMMAGE, VOUS N''AVEZ PAS LA BONNE REPONSE!'
+ #10#13 //on saute une ligne
+ 'La bonne reponse était : '
+ listReponse.strings[index] ; //on construit le message
Application.MessageBox(PChar(messageTmp),'RESULTAT SUR CETTE QUESTION',MB_ICONINFORMATION + MB_OK) ;
end;
index := index+1 ; //on passe a laquestion suivante
// recupere le nombre de question (<=> le nombre d'élement dans la liste)
nbrQuestion := listQuestion.Count ;
if index >= nbrQuestion then // on verifie si il reste des questions
begin
messageTmp := 'Vous obtenez une note de : ' + IntToStr(cptBonneRep) + '/' + IntToStr(nbrQuestion) ;
Application.MessageBox( PChar(messageTmp) ,'RESULTAT FINAL',MB_ICONINFORMATION + MB_OK) ;
BtnValid.Enabled := false ; // on desactive le bouton car il n'y a plus de questions
end else
begin
LblQuestion.caption := listQuestion.strings[index] ; //on l'affiche
EdtReponse.Text := '' ; //on efface la reponse précedante
end ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
listQuestion.Free; //on detruit les listes
listReponse.Free;
end;
procedure TForm1.OnShow(Sender: TObject);
begin
media := TMediaPlayer.Create(form1);
media := TMediaPlayer.CreateParented(form1.Handle);
media.FileName := myMp3Location;
media.Open;
media.Play;
end;
procedure TForm1.BtnQuitClick(Sender: TObject);
begin
media.Stop;
application.terminate;
end;
procedure TForm1.EdtReponseKeyPress(Sender: TObject; var Key: Char);
var nbrQuestion : integer ;
messageTmp : string ;
begin
if Key=#32 then //#32 = entrée - #27=echap etc (cherche par google)
begin
if ( uppercase( EdtReponse.Text ) = uppercase( listReponse.strings[index] )) then
begin
Application.MessageBox('FELICITATION, VOUS AVEZ LA BONNE REPONSE!','RESULTAT',MB_ICONINFORMATION + MB_OK) ;
cptBonneRep := cptBonneRep + 1 ; // on compte les bonnes reponses
end else
begin
messageTmp := 'DOMMAGE, VOUS N''AVEZ PAS LA BONNE REPONSE!'
+ #10#13 //on saute une ligne
+ 'La bonne reponse était : '
+ listReponse.strings[index] ; //on construit le message
Application.MessageBox(PChar(messageTmp),'RESULTAT SUR CETTE QUESTION',MB_ICONINFORMATION + MB_OK) ;
end;
index := index+1 ; //on passe a laquestion suivante
// recupere le nombre de question (<=> le nombre d'élement dans la liste)
nbrQuestion := listQuestion.Count ;
if index >= nbrQuestion then // on verifie si il reste des questions
begin
messageTmp := 'Vous obtenez une note de : ' + IntToStr(cptBonneRep) + '/' + IntToStr(nbrQuestion) ;
Application.MessageBox( PChar(messageTmp) ,'RESULTAT FINAL',MB_ICONINFORMATION + MB_OK) ;
BtnValid.Enabled := false ; // on desactive le bouton car il n'y a plus de questions
end else
begin
LblQuestion.caption := listQuestion.strings[index] ; //on l'affiche
EdtReponse.Text := '' ; //on efface la reponse précedante
end ;
end;
Sat83
Messages postés166Date d'inscriptionmardi 11 novembre 2003StatutMembreDernière intervention13 octobre 2008 5 mai 2008 à 17:59
Plusieurs remarques:
- tu peux creer des fonction/procedure pour les trucs qui se repetent.
-Pour tes variables globales
(TStringList...), tu peux les déclarer dans ta classe (je l'avais mis
dans mon exemple, je ne sais pas pourquoi tu les as enlevés?)
- petit conseil: essai
d'avoir un programme complet et qui marche avant d'ajouter des
fonctionnalités "superflu" (TMediaPlayer). C'est plus facile une fois
qu'on a une base qui marche bien d'ajouter des fonctionnalités pour
améliorer son programme et le finaliser, plutot que d'ajouté des trucs
pas necessaire dès le depart.
Voilà un exmeple qui marche avec la fonctionnalité lorsque tu appuis sur Enter :
----------------------------------------------------------------------------
unit uMain;
procedure CheckQuestion; // declaration de la procedure
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BtnValidClick(Sender: TObject);
begin
CheckQuestion ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
listQuestion := TStringList.Create; //on creer la liste de questions
listReponse := TStringList.Create; // on creer la liste de reponses
listQuestion.LoadFromFile('C:\question.txt'); //on charge depuis le fichier
listReponse.LoadFromFile('C:\reponse.txt'); //on charge depuis le fichier
index := 0;
LblQuestion.caption := listQuestion.strings[index];
cptBonneRep := 0 ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
listQuestion.Free; //on detruit les listes
listReponse.Free;
end;
procedure TForm1.BtnQuitClick(Sender: TObject);
begin
Close ; // Close c'est mieux que application.Terminate
end;
procedure TForm1.CheckQuestion;
var nbrQuestion : integer ;
messageTmp : string ;
begin
if ( uppercase( EdtReponse.Text ) = uppercase( listReponse.strings[index] )) then
begin
Application.MessageBox('FELICITATION, VOUS AVEZ LA BONNE REPONSE!','RESULTAT SUR CETTE QUESTION',MB_ICONINFORMATION + MB_OK) ;
cptBonneRep := cptBonneRep + 1 ;
end else
begin
messageTmp := 'DOMMAGE, VOUS N''AVEZ PAS LA BONNE REPONSE!'
+ #10#13 //on saute une ligne
+ 'La bonne reponse était : '
+ listReponse.strings[index] ;
Application.MessageBox(PChar(messageTmp),'RESULTAT SUR CETTE QUESTION',MB_ICONINFORMATION + MB_OK) ;
end;
index := index+1 ; //on passe a laquestion suivante
nbrQuestion := listQuestion.Count ;
if index >= nbrQuestion then // on verifie qu'il reste des questions
begin
messageTmp := 'Vous obtenez une note de : ' + IntToStr(cptBonneRep) + '/' + IntToStr(nbrQuestion) ;
Application.MessageBox( PChar(messageTmp) ,'RESULTAT FINAL',MB_ICONINFORMATION + MB_OK) ;
BtnValid.Enabled := false ;
end else
begin
LblQuestion.caption := listQuestion.strings[index] ; //on l'affiche
EdtReponse.Text := '' ; //on efface la reponse précedante
end ;
end;
procedure TForm1.EdtReponseKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = #13) and BtnValid.Enabled then
begin
CheckQuestion ;
end ;
end;