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 :

[D2009] Array dynamique dans Array


Sujet :

Langage Delphi

  1. #1
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut [D2009] Array dynamique dans Array
    Bonjour à toutes et à tous,

    J'ai besoin de déclarer différent tableaux constants :
    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
    {$REGION 0}
    Const
      ListeSortie0 : Array[0..4] of String =
      (
      'ggggggggggggggERZGFEZRgg',
      'gggggggggggZERGZFggggg',
      'gggggggggggggRZEGggg',
      'gggggggggggZEggggg',
      'ggREZFEZRGFERgggggggggggggg'
      );
    {$ENDREGION 0}
     
    {$REGION 1}
    Const
      ListeSortie1 : Array[0..0] of String =
      ('TTTTTTTTTTTTTTTTTTT');
    {$ENDREGION 1}
    Ensuite dans une procédure OnClick commune à différent Boutton, j'ai besoin de copier l'un de ces tableaux dans un tableau dynamique Mais cela ne fonctionne pas voilà mon code :

    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
    42
    43
    44
    45
    procedure TFConversion.sBitBtnCommunClick(Sender: TObject);
    Var
      Path : array[0..MAX_PATH] of Char;
      i: Integer;
      Liste: array of String;
    begin
    // Récupération du chemin Mes doc du poste
      SHGetSpecialFolderPath(0,Path, CSIDL_PERSONAL,False);
      Case TsBitBtn(Sender).Tag of
        0:{Log1}
          Begin
            SetLength(Liste, Length(ListeSortie0));
            Liste := Copy(listeSortie0);
            EditSortie.Text := IncludeTrailingPathDelimiter(StrPas(Path))+'ECRITURES.TXT';
          end;
        1:{Log2}
          Begin
            SetLength(Liste, Length(ListeSortie1));
            Liste := Copy(listeSortie1);
            EditSortie.Text := IncludeTrailingPathDelimiter(StrPas(Path));
          end;
        2:{Log3}
          Begin
          end;
        3:{Log4}
          Begin
          end;
        4:{Log5}
          Begin
          end;
        6:{Log6}
          Begin
          end;
      End;
     
    // On mets à jour les choix du profil de sortie
      With sComboBoxProfils do
      Begin
        Items.Clear;
        for i := Low(Liste) to High(Liste) do
          Items.Add(Liste[i]);
      end;
     
      if sComboBoxProfils.Items.Count > 0 then sComboBoxProfils.ItemIndex := 0;
    end;
    Mais cela bloque sur la ligne : Liste := Copy(listeSortie0); avec erreur type incompatible.

    J"ai également essayer cela
    Move(ListeSortie0[0],Liste[0],Length(ListeSortie0));

    Mais je ne recopie que la première valeur. Mon but etant d'éviter de passer par une boucle.

    Merci de vos lumières.

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 70
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 49
    Points : 51
    Points
    51
    Par défaut
    Citation Envoyé par BuzzLeclaire Voir le message
    Mais cela bloque sur la ligne : Liste := Copy(listeSortie0); avec erreur type incompatible.
    Normal, la fonction Copy n'est pas faite pour ça. Utilisez F1 !

    Citation Envoyé par BuzzLeclaire Voir le message
    Mon but etant d'éviter de passer par une boucle.
    Pourquoi ?

  3. #3
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Michel Devaud Voir le message
    Normal, la fonction Copy n'est pas faite pour ça. Utilisez F1 !



    Pourquoi ?
    Tu va rire mon F1 sur mon delphi 2009 tout neuf bug.. mort de rire. Et puis la fonction copy est faite pour ca justement !! Mais je n'ai vue des exemples qu'avec 2 tableaux de Array dû même type.

    Pourquoi ?, je préfère en apprendre d'avantage, faire une boucle, bah en fait là c'est ce que j'ai fais, mais je voudrais pas passer à coter d'une belle fonction...

    Ton aide m'a été trés précieuse... Merci

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 70
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 49
    Points : 51
    Points
    51
    Par défaut
    F1 -> Copy : Renvoie une sous-chaîne d'une chaîne ou un segment de tableau dynamique. function Copy(S; Index, Count: Integer): array;

    Citation Envoyé par BuzzLeclaire Voir le message
    Move(ListeSortie0[0],Liste[0],Length(ListeSortie0));
    Et en écrivant : Move(ListeSortie0[0],Liste[0],SizeOf(ListeSortie0)) ?

  5. #5
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    Salut

    Comme tu as D2009, je te fais un petit cadeaux (voir StrArray.zip) pour ton code, a utiliser comme dans l'exemple :

    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
     
    uses StrArray;
     
     
    var
      ListeSortie : array[0..1] of TStringArray;
     
    procedure TForm1.Button1Click(Sender: TObject);
    var Liste : TStringArray;
        Tag   : integer;
    begin
      Tag := 0;
      case Tag of
        0 : Liste := ListeSortie[tag];
        1 : Liste := ListeSortie[tag];
      end;
     
      if Liste <> 0 then
        ListBox1.Items.Assign(Liste);
    // ou Liste.AssignTo(ListBox1.Items);
    end;
     
     
    initialization
      ListeSortie[0].PushClear([
        'ggggggggggggggERZGFEZRgg',
        'gggggggggggZERGZFggggg',
        'gggggggggggggRZEGggg',
        'gggggggggggZEggggg',
        'ggREZFEZRGFERgggggggggggggg'
      ]);
     
      // huhuhu (regarder le class operator implicit de TStringArray ;)
      ListeSortie[1] := 'TTTTTTTTTTTTTTTTTTT';
     
    finalization
      ListeSortie[1].Finalize;
      ListeSortie[0].Finalize;
     
    end.


    sinon pour ton probleme :


    il faut faire :

    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
     
    type
      TDynArray = array of string;
     
    var
      ListeSortie : array of TDynArray;
     
    ...
    var
      Liste : TDynArray;
    begin
      SetLength(ListeSortie, 2);
      SetLength(ListeSortie[0], 5);
      SetLength(ListeSortie[1], 1);
     
      ...
     
      ...
      Liste := ListeSortie[n];
    end;
    Fichiers attachés Fichiers attachés
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  6. #6
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    Voici une astuce que j'utilise souvent pour ce genre de structures :

    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
     
    // une fiche, 1 listbox, 2 boutons, Tag à 0 et 1, même procédure Click
     
    const
      ListeSortie0 : Array[0..4] of String =
      (
      'ggggggggggggggERZGFEZRgg',
      'gggggggggggZERGZFggggg',
      'gggggggggggggRZEGggg',
      'gggggggggggZEggggg',
      'ggREZFEZRGFERgggggggggggggg'
      );
     
      ListeSortie1 : Array[0..0] of String =
      ('TTTTTTTTTTTTTTTTTTT');
     
    type
      TItems = array[Word] of string;
      PItems = ^TItems;
      TListInfo = record
        Count: Integer;
        Items: PItems;
      end;
     
    const
      Listes: array[0..1] of TListInfo = (
        (Count: Length(ListeSortie0); Items: @ListeSortie0),
        (Count: Length(ListeSortie1); Items: @ListeSortie1)
      );
     
    procedure TForm1.Button1Click(Sender: TObject);
    var
      cListe: Integer;
      cIndex: Integer;
    begin
      ListBox1.Clear;
      cListe := TButton(Sender).Tag;
      for cIndex := 0 to Listes[cListe].Count - 1 do
        ListBox1.Items.Add(Listes[cListe].Items[cIndex]);
    end;
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  7. #7
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Hallucinant...

    Je suis plus que comblé.

    Vos 2 propositions sont tout simplement trés intelligente, jamais j'aurais pondu un truc pareil !!!

    Merci Paul TOTH et Dr. Who

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

Discussions similaires

  1. Comment compter le nombre de ligne dans un Array dynamique?
    Par NewYork dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 07/03/2011, 17h21
  2. Réponses: 4
    Dernier message: 09/07/2006, 14h41
  3. [Tableaux] Array dynamique
    Par Yjo dans le forum Langage
    Réponses: 3
    Dernier message: 26/05/2006, 11h31
  4. Donner un nom dynamique à un Array
    Par uado dans le forum ASP
    Réponses: 5
    Dernier message: 27/01/2006, 15h54
  5. passage en paramètre d'un array dynamique 2D
    Par Guigui_ dans le forum Langage
    Réponses: 4
    Dernier message: 27/11/2002, 19h47

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