IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

problem avec lecture de fichier!!(débutant)


Sujet :

Delphi

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 8
    Points : 4
    Points
    4
    Par défaut problem avec lecture de fichier!!(débutant)
    Bjr, j'ai un problem au moment du lecture de mon fichier.
    je veux donc enregistrer tout ce k'un utilisateur tappe dans 4 labels diférents
    et les aficher dans un memo...ca ne fonctionne pas...

    procedure TForm7.ButtonClickBackClick(Sender: TObject);
    begin
    form7.hide;
    form3.show;
    end;

    procedure TForm7.Button1Click(Sender: TObject);
    var
    Bestand12 : TextFile;
    bestand13 : TextFile;
    Bestand14 : TextFile;
    bestand15 : TextFile;






    begin

    AssignFile(Bestand12,'C:\FanClubName.txt');
    if not FileExists('c:\NameFanClubName.txt')
    then rewrite(bestand12)

    else append(bestand12);
    rewrite(bestand12);
    Write(Bestand12,Form7.EditFanClubName.Text);

    CloseFile(Bestand12);

    AssignFile(Bestand13,'C:\FanClubAdresse.txt');
    if not FileExists('c:\FanClubAdresse.txt')then rewrite(bestand13)
    else append(bestand13);
    rewrite(bestand13);
    Write(Bestand13,Form7.EditFanClubAdresse.Text);

    CloseFile(Bestand13);



    AssignFile(Bestand14,'C:\FanClubAdresse2.txt');
    if not FileExists('c:\NameFanClubAdresse2.txt')
    then rewrite(bestand14)

    else append(bestand14);
    rewrite(bestand14);
    Write(Bestand14,Form7.EditFanClubAdresse2.Text);

    CloseFile(Bestand14);

    AssignFile(Bestand15,'C:\FanClubMessage.txt');
    if not FileExists('c:\FanClubMessage.txt')then rewrite(bestand15)
    else append(bestand15);
    rewrite(bestand15);
    Write(Bestand15,Form7.EditFanClubMessage.Text);

    CloseFile(Bestand15);







    showmessage('You are Now a Member of the FanClub PNK');





    end;

    var
    FanClubName : string;
    L:string;

    begin

    begin
    //Memo2.clear; // efface toutes les lignes du mémo
    AssignFile(Bestand12,'C:\FanClubName.txt'); //A partir de maintenant, F désigne le fichier portant comme nom le nom récupéré par OpenDialog1
    Reset(Bestand12); // ouvre le fichier F (F doit déjà exister)
    while not EOF(Bestand12) do // tant que l'on est pas arrivé à la fin du fichier
    begin
    Readln(Bestand12,L);// lit ligne du fichier et la met dans L puis se positionne sur la ligne suivante
    MemoFanClub.Lines.add(L); //Rajoute le contenu de L à la fin du mémo
    end;
    CloseFile(Bestand12); // ferme le fichier
    end;
    end;

  2. #2
    Membre éprouvé

    Profil pro
    Inscrit en
    Mai 2003
    Messages
    582
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mai 2003
    Messages : 582
    Points : 915
    Points
    915
    Par défaut
    Simplement en ajoutant des indentations...
    on voit déjà un petit problème....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    AssignFile(Bestand12,'C:\FanClubName.txt');
    if not FileExists('c:\NameFanClubName.txt') then
        rewrite(bestand12)  //-> #1 - ici on Creer un nouveau fichier et on l'ouvre
    else
        append(bestand12);  //-> #2 - ici on ouvre simplement le fichier...
                            //       (on veut ajouter du text au fichier existant)
    rewrite(bestand12); //-> ici comme en #1, est toujours executé
                        //   (rewrite (faire F1) Remet aussi a zero un fichier existant)
    Write(Bestand12,Form7.EditFanClubName.Text);
    CloseFile(Bestand12);
    je te propose simplement de re-formatter ton code
    pour qu'il soit plus lisible....pour toi... et nous tous...

    Ensuite,
    le code suivant n'est dans aucune procèdure selon moi...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    var 
    FanClubName : string; 
    L:string; 
     
    begin 
     
    begin 
    //Memo2.clear; // efface toutes les lignes du mémo 
    AssignFile(Bestand12,'C:\FanClubName.txt'); //A partir de maintenant, F désigne le fichier portant comme nom le nom récupéré par OpenDialog1 
    Reset(Bestand12); // ouvre le fichier F (F doit déjà exister) 
    while not EOF(Bestand12) do // tant que l'on est pas arrivé à la fin du fichier 
    begin 
    Readln(Bestand12,L);// lit ligne du fichier et la met dans L puis se positionne sur la ligne suivante 
    MemoFanClub.Lines.add(L); //Rajoute le contenu de L à la fin du mémo 
    end; 
    CloseFile(Bestand12); // ferme le fichier 
    end; 
    end;
    ca devrait sauter au yeux si on utilise mieux
    les indentations...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    procedure TForm7.Button1Click(Sender: TObject); 
    var 
        Bestand12 : TextFile; 
        bestand13 : TextFile; 
        Bestand14 : TextFile; 
        bestand15 : TextFile; 
    begin 
        //*** Mettre le code....
        //*** en respectant les indentations....
        if a=0 then
        begin
             // si vrai
        end
        else
        begin
             // si faux
        end;
    end;

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 8
    Points : 4
    Points
    4
    Par défaut re
    g donc changé en suivant les intruction...


    pour ecrire:
    procedure TForm7.Button1Click(Sender: TObject);
    var
    Bestand12 : TextFile;


    begin
    AssignFile(Bestand12,'C:\FanClubName.txt');
    if not FileExists('c:\NameFanClubName.txt') then Rewrite(bestand12) else Append(bestand12);
    Writeln(Bestand12,Form7.EditFanClubName.Text);
    Writeln(Bestand12,Form7.EditFanClubAdresse.Text);
    Writeln(Bestand12,Form7.EditFanClubAdresse2.Text);
    Writeln(Bestand12,Form7.EditFanClubMessage.Text);
    CloseFile(Bestand12);

    Showmessage('You are now a member of the FanClub PNK');
    end;

    mnt g une faute 'method identifier expected'
    pour lire:
    var
    L:string;
    Bestand : TextFile;
    begin
    if not FileExists('c:\NameFanClubName.txt') then exit;

    AssignFile(Bestand12,'C:\FanClubName.txt');
    Reset(Bestand12); // ouvre le fichier F (F doit déjà exister)
    while not EOF(Bestand12) do
    begin
    Readln(Bestand12,L);
    MemoFanClub.Lines.Add(L); end;
    CloseFile(Bestand12);


    end;

  4. #4
    Membre éprouvé

    Profil pro
    Inscrit en
    Mai 2003
    Messages
    582
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mai 2003
    Messages : 582
    Points : 915
    Points
    915
    Par défaut
    c'est que ton code de l'ecture est en dehors de ta procedure...


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    //*** Debut de la procedure ici ***
    procedure TForm7.Button1Click(Sender: TObject);
    var
    Bestand12 : TextFile;
     
     
    begin
    AssignFile(Bestand12,'C:\FanClubName.txt');
    if not FileExists('c:\NameFanClubName.txt') then Rewrite(bestand12) else Append(bestand12);
    Writeln(Bestand12,Form7.EditFanClubName.Text);
    Writeln(Bestand12,Form7.EditFanClubAdresse.Text);
    Writeln(Bestand12,Form7.EditFanClubAdresse2.Text);
    Writeln(Bestand12,Form7.EditFanClubMessage.Text);
    CloseFile(Bestand12);
     
    Showmessage('You are now a member of the FanClub PNK');
    end; //-> ici ta procedure ce termine....
    tu dois mettre ton code comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    procedure TForm7.Button1Click(Sender: TObject);
    var  //-> *** BLOC de déclaration des variable dans la procedure
      Bestand12 : TextFile;
      L:string; // AJOUT d'une variable POUR LA LECTURE  
    begin
      AssignFile(Bestand12,'C:\FanClubName.txt');
      if not FileExists('c:\NameFanClubName.txt') then Rewrite(bestand12) else Append(bestand12);
      Writeln(Bestand12,Form7.EditFanClubName.Text);
      Writeln(Bestand12,Form7.EditFanClubAdresse.Text);
      Writeln(Bestand12,Form7.EditFanClubAdresse2.Text);
      Writeln(Bestand12,Form7.EditFanClubMessage.Text);
      CloseFile(Bestand12);
     
      Showmessage('You are now a member of the FanClub PNK');
     
      //*** ici lecture du fichier dans la meme procedure: ***
      //Memo2.clear; // efface toutes les lignes du mémo 
      AssignFile(Bestand12,'C:\FanClubName.txt'); 
      Reset(Bestand12); // ouvre le fichier F (F doit déjà exister) 
      while not EOF(Bestand12) do // tant que l'on est pas arrivé à la fin du fichier 
      begin 
        Readln(Bestand12,L);// lit ligne du fichier et la met dans L puis se positionne sur la ligne suivante 
       MemoFanClub.Lines.add(L); //Rajoute le contenu de L à la fin du mémo 
      end; 
      CloseFile(Bestand12); // ferme le fichier 
     
    end; //-> ici ta procedure ce termine....

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 8
    Points : 4
    Points
    4
    Par défaut merci bcp !!!
    merci!!! tout roule comme sur des roulettes...
    je realise que j'ai encore bcp a apprendre !!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 04/07/2011, 20h55
  2. probleme avec lecture fichier XML
    Par aztec dans le forum XML/XSL et SOAP
    Réponses: 7
    Dernier message: 24/10/2010, 10h51
  3. Probleme de lecture de fichier swf avec c#
    Par Vince57 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 14/06/2006, 14h18
  4. Probleme de lecture de fichier
    Par ArkAng3 dans le forum MFC
    Réponses: 9
    Dernier message: 11/12/2005, 20h47
  5. [vb.net][xml] probleme de lecture de fichier
    Par graphicsxp dans le forum Windows Forms
    Réponses: 4
    Dernier message: 27/07/2005, 11h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo