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

Langage Delphi Discussion :

Structure d'un tableau dynamique


Sujet :

Langage Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 38
    Par défaut Structure d'un tableau dynamique
    bonjour,

    je viens de me mettre a delphi et je cherche a stocker les données d'un fichier XML dans un tableau.
    je parvient a lire correctement le fichier xml mais je ne sais pas comment le stocker en memoire dans un tableau.
    je voudrais un tableau du type : array(nom_cat : url1, url2, url3 ...)

    merdi d'avance

  2. #2
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Par défaut
    Salut,

    Ton tableau contiendra des chaines de caractères si je ne me trompe pas ?!

    Voici un exemple d'utilisation pour déclarer un tableau, l'agrandir de façon dynamique et le remplir ...

    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
    var
      Form1: TForm1;
      MonTableau:array of string; // on défini le tableau qui va contenir des caractères
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.BtnRemplirClick(Sender: TObject);
    var
    i:integer;
    begin
      for i:=0 to 10 do
      begin
       SetLength(MonTableau,i+1); // On redéfini la taille du tableau
       MonTableau[i]:=IntToStr(i); // Ajout d'une chaine de caractères
      end;
    end;
     
    procedure TForm1.BtnAfficherClick(Sender: TObject);
    var
    i:integer;
    begin
      for i:=0 to high(MonTableau) do // high = jusqu'au dernier enregistrement
      begin
        ShowMessage(MonTableau[i]); // Affichage
      end;
    end;
    En espérant t'avoir aidé
    A++

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 38
    Par défaut
    pour bien faire il me faudrait quelque chose de ce genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    type structCat=record
      cat:string;
      urlArray:array[0..9] of string;
    end;
     
    var  tabCat:array of structCat;
    le probleme c'est que je m'embrouille pour remplir ce tableau de structure

    merci pour cette reponse tres explicite

  4. #4
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Par défaut
    Re,

    C'est plus un soucis d'affectation et d'utilisation alors ...

    Voici un exemple banal ...

    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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    type structCat=record
      cat:string;
      urlArray:array[0..9] of string;
    end;
     
    var
      Form1: TForm1;
      tabCat:array of structCat;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.BtnRemplirClick(Sender: TObject);
    var
    i,j:integer;
    begin
      for i:=0 to 10 do
      begin
        SetLength(tabCat,i+1);
        tabCat[i].cat:='toto'+IntToStr(i);
        for j:=0 to 9 do
        begin
          tabCat[i].urlArray[j]:='tata'+IntToStr(j);
        end;
      end;
    end;
     
    procedure TForm1.BtnAfficherClick(Sender: TObject);
    var
    i,j:integer;
    begin
      for i:=0 to high(tabCat) do
      begin
       ShowMessage(tabCat[i].cat);
        for j:=0 to 9 do
        begin
          ShowMessage(tabCat[i].urlArray[j]);
        end;
      end;
    end;
    J'espère que ca ira

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 38
    Par défaut
    merci beaucoup, j'y voit plus claire

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 38
    Par défaut
    et au fait, comment et où declarer une constante accessible dans toute mon appli, ca serait pour definir le chemin de travail ou je copie mes fichiers?

    genre : const workDirectory = 'c:/tralala';

Discussions similaires

  1. Réponses: 7
    Dernier message: 18/01/2015, 23h57
  2. tableau dynamique provenant d'une structure
    Par VenomX dans le forum C
    Réponses: 4
    Dernier message: 17/07/2007, 10h47
  3. Réponses: 4
    Dernier message: 23/03/2007, 09h40
  4. Tableau dynamique de structures
    Par beb30 dans le forum C
    Réponses: 13
    Dernier message: 29/04/2006, 12h41
  5. TAD matrice (structure + tableau dynamique)
    Par supermanu dans le forum C
    Réponses: 10
    Dernier message: 13/11/2004, 20h04

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