Naviguer dans un tableau d'objets

Inconnu Anonyme Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 19 juin 2005 - 15 juin 2005 à 23:07
Inconnu Anonyme Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 19 juin 2005 - 15 juin 2005 à 23:11
Bonjour. Voila je fais un petit agenda électronique. Il consiste a en
ajouter des personnes avec toutes les informations : nom , prenom,
numero tel etc.





Alors, dans ma premiere unité, on retrouve ceci:





const NB_MAX_COMPTE = 10;





var


Form1: TForm1;


Indice_actuel : integer;


nb_personne : integer;


Nom : string[15];





Tab_personne : array [1..NB_MAX_COMPTE] of TpPersonne;


implementation





{$R *.dfm}





procedure TForm1.FormCreate(Sender: TObject);


begin


Indice_actuel := 0;


Nb_personne := 0;


end;





procedure TForm1.FormShow(Sender: TObject);


begin


affiche_info_gen;


end;





//procédure pour ajouter une nouvelle personne


procedure TForm1.Ajout1Click(Sender: TObject);


var ok_ajout: boolean;


begin


ok_ajout := true;


if Nb_personne = NB_MAX_COMPTE then


begin


Showmessage('Impossible d''ajouter une nouvelle personne, le tableau est plein.');


ok_ajout := false;


end;


if ok_ajout = true then


begin


Showmessage('Saisir les informations de la nouvelle personne.');


Edit1.ReadOnly := false;


Edit2.ReadOnly := false;


Edit3.ReadOnly := false;


Edit4.ReadOnly := false;


Edit5.ReadOnly := false;


Edit6.ReadOnly := false;


Edit7.ReadOnly := false;


Edit8.ReadOnly := false;


MaskEdit1.ReadOnly := false;


MaskEdit2.ReadOnly := false;


MaskEdit3.ReadOnly := false;


Button2.Enabled := true;


Button3.Enabled := true;


Button4.Enabled := true;


Button5.Enabled := true;


Button6.Visible := true;


ComboBox1.Enabled := true;


Indice_actuel := Nb_personne + 1;


Tab_Personne[Indice_actuel] := TpPersonne.Init(Nom);


Nb_personne := Nb_personne + 1;


affiche_info_personne(indice_actuel);


affiche_info_gen;


end;





procedure TForm1.Button6Click(Sender: TObject);


begin


Edit1.ReadOnly := true;


Edit2.ReadOnly := true;


Edit3.ReadOnly := true;


Edit4.ReadOnly := true;


Edit5.ReadOnly := true;


Edit6.ReadOnly := true;


Edit7.ReadOnly := true;


Edit8.ReadOnly := true;


MaskEdit1.ReadOnly := true;


MaskEdit2.ReadOnly := true;


MaskEdit3.ReadOnly := true;


Button6.Visible := false;


ComboBox1.Enabled := false;


end;





procedure TForm1.Button2Click(Sender: TObject);


begin


if Indice_actuel <> 1 then


begin


Indice_actuel := 1;


Affiche_info_personne(Indice_actuel);


affiche_info_gen;


end;


end;





procedure TForm1.Button3Click(Sender: TObject);


begin


if Indice_actuel <> Nb_personne then


begin


Indice_actuel := Nb_personne;


Affiche_info_personne(Indice_actuel);


affiche_info_gen;


end;


end;





procedure TForm1.Button4Click(Sender: TObject);


begin


if Indice_actuel = 1 then


begin


Showmessage('Premier compte');


end


else


begin


Indice_actuel := Indice_actuel - 1;


Affiche_info_personne(Indice_actuel);


affiche_info_gen;


end;


end;





procedure TForm1.Button5Click(Sender: TObject);


begin


if Indice_actuel = Nb_personne then


begin


Showmessage('Dernier compte');


end


else


begin


Indice_actuel := Indice_actuel + 1;


Affiche_info_personne(Indice_actuel);


affiche_info_gen;


end;


end;





end.





Ensuite, ma deuxieme unité:





unit Unit2;





interface


type


TpPersonne = class


private


NomA : string;


public


constructor Init(NomB:string);overload;





procedure set_nom(NomB : string);


function get_nom : string;


end;





constructor TpPersonne.Init(NomB:string);


begin


NomA := NomB;


end;





procedure TpPersonne.set_nom(NomB : string);


begin


NomA := NomB;


end;





function TpPersonne.get_nom : string;


begin


Result := NomA;


end;


end.





Enfin ma 3e unité:





unit Unit3;





interface





uses SysUtils;





Procedure Affiche_info_gen;


procedure affiche_info_personne(Ind : integer);





implementation





uses Unit1, Unit2;





Procedure Affiche_info_gen;


begin


Form1.Edit9.Text := inttostr(Nb_personne);


Form1.Edit10.Text := inttostr(Indice_actuel);


end;





procedure affiche_info_personne(Ind : integer);


begin


Form1.Edit1.Text := Tab_personne[Ind].Get_Nom;


end;





Mon problème : Lorsque je rajoute des personnes dans mon tableau, il
est possible de naviguer dans le tableau à l'exception que les
informations (dans ce cas-ci le nom) disparaient. Pourtant, ma variable
indice_actuel démontre bien qu'il y a bel et bien 2 personnes dans mon
tableau si j'en ajoute 2 ou 3 personnes si j'en ajoute 3 etc.





Merci de votre aide!

1 réponse

Inconnu Anonyme Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 19 juin 2005
15 juin 2005 à 23:11
Désolé de poster 2 fois , mais j'ai oublié de spécifier que
Button2,3,4,5 sont respectivement mes boutons pour naviguer dans mon
tableau : premier,dernier,precedent,suivant.

Ainsi pour le button6 qui est un bouton de confirmation et qui met les edits en lecture seul apres avoir fait les modifications.
0
Rejoignez-nous