Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionunit Unit1; // // grod0026@free.fr le 01/01/2010 // // // Quelques petites remarques // - je stocke dans le fichier le numero (ici de 1 a 11) qui ne sert qu'a la // lisibilité du fichier texte ou sont enregistré les donnéés. // - pour les grandes listes on preferera utiliser des tableaux plutot des // acces a un fichier, surtout que celui ci est un fichier texte // - l ajout ou la suppression ( boutons + et -) ne sont pas faits ainsi que // l'enregistrement de nouvelles valeurs. // - pour le moment l equivalent graphique est "figé" dans un stinggrid // dans un devellopement futur rien n empeche la lecture des donnees // puis création automatique. // - fichier texte peut etre un fichier a acces sequentiel. // - la structure du fichier peut etre modifié du genre // nom , n°combo ,lien // - on fait deux procedures de recherche qui peut etre reduite a 1 seule // // // // // strucure des données enregistrés dans 'c:\CB1Cb.txt' // numero | nom | N° combo |lien service | lien batiment // 1 | service1 | 1 | 0 | 0 // 2 | batmentA | 2 | 1 | 0 // 3 | etage 01 | 3 | 1 | 2 // 4 | batimentB | 2 | 1 | 0 // 5 | service2 | 1 | 0 | 0 // 6 | etage03 | 3 | 1 | 4 // 7 | batimentC | 2 | 5 | 0 // 8 | etage04 | 3 | 5 | 7 // 9 | etage05 | 3 | 5 | 7 // 10 etage06 | 3 | 5 | 7 // 11 etage02 | 3 | 1 | 2 // // equivaut a // // service1 -> batimentA -> etage01 // -> etage02 // -> batimentB -> etage03 // // service2 -> batimentC -> etage04 // -> etage05 // -> etage06 // // interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, jpeg, StdCtrls, ShellApi, Menus, Mask, Grids; var FlistBox: TextFile; type TForm1 = class(TForm) Label3: TLabel; Label4: TLabel; Label5: TLabel; Etotal: TEdit; CB1: TComboBox; CB2: TComboBox; CB3: TComboBox; BAjoutCB1: TButton; MemoCB1: TMemo; MemoCB2: TMemo; MemoCB3: TMemo; sg1: TStringGrid; Label13: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; b6: TButton; Button5: TButton; procedure BAjoutCB1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure CB1Click(Sender: TObject); procedure CB2Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; var Form1: TForm1; comboBox: TComboBox; pointCB1: integer; // valeur choisie dans Cb 1 pointCB2: integer; // valeur choisie dans Cb 2 pointCB3: integer; // valeur choisie dans Cb 3 TextaLire: string; total: string; rubri: array[1..5, 1..100] of string; // les valeurs text 1 a 5 les champs et 1 a 100 les valeurs totfi: integer; (* raz puis nombre total de valeurs lues dans le fichier *) Narech2: integer; // num a rechercher pour cb2 Narech3: integer; // num a rechercher pour cb3 implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); // a la creation on ne cherche les donnees que du Combo Box 1 // les autres combo seront remplis avec les donnees du cb precedent var j: integer; Textmemo1: string[200]; begin cb1.Clear; if FileExists('c:\CB1Cb.txt') then begin AssignFile(Flistbox, 'c:\CB1Cb.txt'); reset(Flistbox); CB1.Clear; CB2.Clear; CB3.Clear; cb2.Enabled := false; cb3.Enabled := false; total := ''; totfi := 0; while not Eof(Flistbox) do begin Textmemo1 := ''; for j := 1 to 5 do begin readln(flistbox, TextaLire); rubri[j, totfi] := TextaLire; Textmemo1 := Textmemo1 + TextaLire + ' '; end; if rubri[3, totfi] = '1' then begin; CB1.Items.Add(rubri[2, totfi]); memoCB1.Lines.Add(rubri[2, totfi]); end; inc(totfi); end; closefile(flistbox); end; sg1.ColCount := 4; sg1.RowCount := 7; sg1.Cells[1, 1] := 'service 1 -->'; sg1.Cells[2, 1] := 'batiment A -->'; sg1.Cells[3, 1] := 'Etage01'; sg1.Cells[2, 2] := ' -->'; sg1.Cells[3, 2] := 'Etage02'; sg1.Cells[1, 3] := ' -->'; sg1.Cells[2, 3] := 'batiment B -->'; sg1.Cells[3, 3] := 'Etage03'; sg1.Cells[1, 4] := 'service 2 -->'; sg1.Cells[2, 4] := 'batiment C -->'; sg1.Cells[3, 4] := 'Etage04'; sg1.Cells[3, 5] := 'Etage05'; sg1.Cells[3, 6] := 'Etage06'; end; procedure TForm1.BAjoutCB1Click(Sender: TObject); var ligne: string; begin ligne := InputBox('Nouveau COMBOBox', 'entrez le nom', ''); if ligne <> '' then CB1.Items.Add(ligne); // on sauvegarde end; procedure TForm1.CB1Click(Sender: TObject); // Click var j: integer; i: integer; Textmemo2: string[200]; aRech: string[200]; begin Cb2.Clear; cb2.Enabled := true; Cb3.Clear; cb3.Enabled := False; combobox := TCombobox(Sender); pointCB1 := CB1.ItemIndex; // indique l indice de l element total := combobox.Items[pointCB1]; Etotal.Text := total; aRech := total; Narech2 := 0; i := 0; if FileExists('c:\CB1Cb.txt') then begin AssignFile(Flistbox, 'c:\CB1Cb.txt'); reset(Flistbox); i := 0; // on recherche a quel item correspont arech while not eof(Flistbox) do begin for j := 1 to 5 do begin readln(flistbox, TextaLire); if j = 2 then if TextaLire = aRech then Narech2 := i + 1; end; inc(i); end; reset(Flistbox); //se remet au debut memoCB2.Clear; i := 0; // puis on recherche while not Eof(Flistbox) do begin Textmemo2 := ''; for j := 1 to 5 do begin readln(flistbox, TextaLire); Textmemo2 := Textmemo2 + TextaLire + ' '; rubri[j, i] := Textalire; end; if rubri[3, i] = '2' then begin if rubri[4, i] = inttostr(Narech2) then begin memoCB2.Lines.Add(rubri[2, i]); CB2.Items.Add(rubri[2, i]); end; end; inc(i); end; end; end; procedure TForm1.CB2Click(Sender: TObject); var j: integer; i: integer; Textmemo2: string[200]; aRech: string[200]; begin CB3.Clear; CB3.Enabled := true; memoCB3.Clear; combobox := TCombobox(Sender); pointCB2 := CB2.ItemIndex; // indique l indice de l element total := combobox.Items[pointCB2]; Etotal.Text := total; aRech := total; Narech3 := 0; i := 0; if FileExists('c:\CB1Cb.txt') then begin AssignFile(Flistbox, 'c:\CB1Cb.txt'); reset(Flistbox); i := 0; // on recherche a quel item correspont arech while not eof(Flistbox) do begin for j := 1 to 5 do begin readln(flistbox, TextaLire); if j = 2 then if TextaLire = aRech then Narech3 := i + 1; end; inc(i); end; reset(Flistbox); //se remet au debut i := 0; while not Eof(Flistbox) do begin Textmemo2 := ''; for j := 1 to 5 do begin readln(flistbox, TextaLire); Textmemo2 := Textmemo2 + TextaLire + ' '; rubri[j, i] := Textalire; end; if rubri[3, i] = '3' then begin if rubri[5, i] = inttostr(Narech3) then begin memoCB3.Lines.Add(rubri[2, i]); CB3.Items.Add(rubri[2, i]); end; end; inc(i); end; end; end; begin end.