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 :

2 pointeurs Record en 1


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 2 pointeurs Record en 1
    Bonjour à toutes et à tous,

    Ca faisait longtemps.

    J'utilise cette déclaration :

    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
     
    Type
      PFileStrucQDA_Cpt = ^TFileStrucQDA_Cpt;
      TFileStrucQDA_Cpt = packed record
                private __INT_TYPE       : array[0..0]  of AnsiChar; // 1 (alphanumérique)
                private __INT_COMPTE     : array[0..7]  of AnsiChar; // 8
                private __INT_LIB        : array[0..29] of AnsiChar; // 30
                private __INT_CLEALPHA   : array[0..6]  of AnsiChar; // 7
                private __INT_DEBNm1     : array[0..12] of AnsiChar; // 13
                private __INT_CRENm1     : array[0..12] of AnsiChar; // 13
                private __INT_DEBNm2     : array[0..12] of AnsiChar; // 13
                private __INT_CRENm2     : array[0..12] of AnsiChar; // 13
                private __INT_CPTCOLLEC  : array[0..7]  of AnsiChar; // 8
                private __INT_ADR1       : array[0..29] of AnsiChar; // 30
                private __INT_ADR2       : array[0..29] of AnsiChar; // 30
                private __INT_ADRVille   : array[0..29] of AnsiChar; // 30
                private __INT_Tel        : array[0..19] of AnsiChar; // 20
                private __INT_Flag       : array[0..0]  of AnsiChar; // 1
                private __INT_TypeCPT    : array[0..0]  of AnsiChar; // 1
                private __INT_CPTCentral : array[0..0]  of AnsiChar; // 1
                private __INT_DomBancaire: array[0..29] of AnsiChar; // 30
                private __INT_RIB        : array[0..29] of AnsiChar; // 30
                private __INT_ModReg     : array[0..1]  of AnsiChar; // 2
                private __INT_NbJrsEch   : array[0..1]  of AnsiChar; // 2
                private __INT_TermEch    : array[0..1]  of AnsiChar; // 2
                private __INT_DepCalcEch : array[0..1]  of AnsiChar; // 2
                private __INT_CodeTVA    : array[0..1]  of AnsiChar; // 2
                private __INT_CptCtPartie: array[0..7]  of AnsiChar; // 8
                private __INT_NbJrsEchs  : array[0..2]  of AnsiChar; // 3
                private __INT_FlagTVA    : array[0..0]  of AnsiChar; // 1
                private __INT_Fax        : array[0..19] of AnsiChar; // 20
                private __INT_ModReg4Pos : array[0..3]  of AnsiChar; // 4
                private __INT_Groupe4    : array[0..7]  of AnsiChar; // 8
                private __INT_Siret      : array[0..13] of AnsiChar; // 14
                private __INT_EditM2     : array[0..0]  of AnsiChar; // 1
                private __INT_Profession : array[0..29] of AnsiChar; // 30
                private __INT_Pays       : array[0..49] of AnsiChar; // 50
                private __INT_JNLTreso   : array[0..2]  of AnsiChar; // 3
                private __INT_PersMoral  : array[0..0]  of AnsiChar; // 1
                private __INT_BonAPayer  : array[0..0]  of AnsiChar; // 1
     
                private __INT_DEF        : array[0..14] of AnsiChar; // 15
     
                private __FinLigne       : array[0..1]   of AnsiChar; // 2
      end;

    et celle-ci

    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
     
    Type
      PFileStrucQDA_Jnx = ^TFileStrucQDA_Jnx;
      TFileStrucQDA_Jnx = packed record
                private __INT_TYPE       : array[0..0]  of AnsiChar; // 1 (alphanumérique)
                private __INT_COMPTE     : array[0..7]  of AnsiChar; // 8
                private __INT_JNL2c      : array[0..1]  of AnsiChar; // 2
                private __INT_FOLIO      : array[0..2]  of AnsiChar; // 3
                private __INT_DATE       : array[0..5]  of AnsiChar; // 6
                private __INT_CODELIB    : array[0..0]  of AnsiChar; // 1
                private __INT_LIBLibre   : array[0..19] of AnsiChar; // 20
                private __INT_SENS       : array[0..0]  of AnsiChar; // 1
                private __INT_MTSIGNE    : array[0..12] of AnsiChar; // 13
                private __INT_CPTCTPARTIE: array[0..7]  of AnsiChar; // 8
                private __INT_DATEECH    : array[0..5]  of AnsiChar; // 6
                private __INT_CODELETTR  : array[0..1]  of AnsiChar; // 2
                private __INT_CODESTATS  : array[0..2]  of AnsiChar; // 3
                private __INT_NUMPIECE5c : array[0..4]  of AnsiChar; // 5
                private __INT_CODEAFF    : array[0..9]  of AnsiChar; // 10
                private __INT_QUANTITE1  : array[0..9]  of AnsiChar; // 10
                private __INT_NUMPIECE8c : array[0..7]  of AnsiChar; // 8
                private __INT_DEVISE     : array[0..2]  of AnsiChar; // 3
                private __INT_JNL3c      : array[0..2]  of AnsiChar; // 3
                private __INT_FLAGTVA    : array[0..0]  of AnsiChar; // 1
                private __INT_CODETVA    : array[0..0]  of AnsiChar; // 1
                private __INT_METHTVA    : array[0..0]  of AnsiChar; // 1
                private __INT_LIBECRITURE: array[0..29] of AnsiChar; // 30
                private __INT_CODETVA2c  : array[0..1]  of AnsiChar; // 2
                private __INT_NUMPIECE10c: array[0..9]  of AnsiChar; // 10
                private __INT_RESERVE    : array[0..9]  of AnsiChar; // 10
                private __INT_MTDEVISE   : array[0..12] of AnsiChar; // 13
                private __INT_PIECEJOINTE: array[0..11] of AnsiChar; // 12
                private __INT_QUANTITE2  : array[0..9]  of AnsiChar; // 10
                private __INT_NUMUNIQ    : array[0..9]  of AnsiChar; // 10
                private __INT_CodeOP     : array[0..3]  of AnsiChar; // 4
                private __INT_DATASYST   : array[0..13]  of AnsiChar; // 14
     
                private __FinLigne       : array[0..1]   of AnsiChar; // 2
     
    end;
    Ces deux déclarations me servent à lire un fichier text qui peut contenir ces 2 longueurs, pour y arriver aujourd'hui je découpe le fichier en 2, de la sorte :

    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
     
    procedure QDAFileCesure(Fichier: TStringList; Chemin: String);
    Var
      i,j : integer;
      FileCpt, FileEcr: TStringList; // Permet de découper le fichier en 2 autres
    Begin
      FileCpt := TStringList.Create;
      FileEcr := TStringList.Create;
      Try
        for i := 0 to Fichier.Count - 1 do
        begin
          With TStringList.Create do
          begin
            try
              LoadFromFile(Fichier[i]);
              for j := 0 to Count - 1 do
              begin
                if LeftStr(Strings[j],1) = 'C'
                then FileCpt.Add(Strings[j])
                else
                begin
                  if LeftStr(Strings[j],1) = 'M'
                  then FileEcr.Add(Strings[j])
                end;
              End;
            finally
              Free;
            end;
          end;
        end;
        FileCpt.SaveToFile(Chemin+'QDAFileCpt.tmp');
        FileEcr.SaveToFile(Chemin+'QDAFileEcr.tmp');
      Finally
        FileCpt.Free;
        FileEcr.Free;
      End;
    End;
    et ensuite j'utilise mes structures sur l'un et l'autre fichier avec FView

    Je sais que si la première ligne de mon fichier, le caractère 1 est un 'C' c'est la strucutre TFileStrucQDA_Cpt, mais si c'est un 'M' c'est la structure TFileStrucQDA_Jnx.
    PS (pour les puristes) : je souhaite conserver if .... = 'C' et if .... = 'M' (dans le futur je pourrais avoir d'autre lettre et dans ce cas je ferais un case indexStr

    Existe-til un moyen de jumelée ces 2 structures ? où Comment éviter de découper mon fichier en 2 ?


    Merci.

  2. #2
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Si en taille tes deux lignes sont identiques tu peux passer par un case dans un record

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Type
      TMonRecord = record
        case Integer of
          0: (LigneTotal : Array[0..TailleTotale] of AnsiChar); 
          1: (TypeC : TFileStrucQDA_Cpt);
          2: (TypeM : TFileStrucQDA_Jnx);
      end;
    Puis tu appels selon le type

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    var
      MonRecord : TMonREcord
    begin
      if MonRecord.LigneTotal[0] = 'C' then
        MonRecord.TypeC. ...
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

  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
    Bonjour Rayek,

    Comme tu peux le voir, rien que la troisième ligne de chacun des records sont différentes, et surtout la longueur total d'une ligne.

    Merci.

  4. #4
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    A tester quand même

    TailleMax = La taille de la ligne la plus grande

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
    Type
      TMonRecord = record
        case Integer of
          0: (LigneTotal : Array[0..TailleMax] of AnsiChar); 
          1: (TypeC : TFileStrucQDA_Cpt);
          2: (TypeM : TFileStrucQDA_Jnx);
      end;

    puis tu appels quand même

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    var
      MonRecord : TMonREcord
    begin
      MonRecord.LigneTotal := TaListe[0];
     
      if MonRecord.LigneTotal[0] = 'C' then
        MonRecord.TypeC. .
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

  5. #5
    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
    Je comprends bien ce que tu veux faire, mais la lecture se passe ainsi

    Cas 1
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
      FV  := TFileView.Create(Fichier);
      try
        if FV.Loaded then
        begin
          Count := ((FV.FileSize) div SizeOfFileStrucQDA_Jnx); // nombre de lignes
          for i := 0 to count-1 do
          begin
            TStringTempo.Add(Trim(PFileStrucQDA_Jnx(Pointer(Integer(FV.View) + (SizeOfFileStrucQDA_Jnx*i)))^.__INT_JNL3c));
    // ...

    Cas 2
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
      FV  := TFileView.Create(Fichier);
      try
        if FV.Loaded then
        begin
          Count := ((FV.FileSize) div SizeOfFileStrucQDA_Cpt); // nombre de lignes
          for i := 0 to count-1 do
          begin
          TStringTempo.Add(
            Trim(PFileStrucQDA_Cpt(Pointer(Integer(FV.View) + (SizeOfFileStrucQDA_Cpt*i)))^.__INT_COMPTE)
            + '@' +
            Trim(PFileStrucQDA_Cpt(Pointer(Integer(FV.View) + (SizeOfFileStrucQDA_Cpt*i)))^.__INT_LIB)
            );
    // ...

    Là je suis face à mon fichier mais coupé en deux avant, donc j'ai bien 2 fichiers distinct dont la structure des lignes est identiques.

    Je pourrais aussi forcer une taille de ligne identique, genre je passes toutes mes lignes à 900 caractères, mais je serais quand même face à 2 structures différentes !!

    Et dans ton exemple je dois faire cohabiter 2 poiteurs (record) différents ?

    Merci

  6. #6
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Exemple simple ^^

    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
     
    Type
      MonRecord = record
        case integer of
          0: (Total : Array [0.9] of AnsiChar);
          1: (
             Moitier1, 
             Moitier2 : Array [0..4] of AnsiChar);
          2: ( 
              UnRecord : record
                Tier1,
                Tier2,
                Tier3 : Array [0..3] of Ansichar;
                LeReste : Char;
              end;
             );
          3: ( Les4Premiers : Array [0..3] of Ansichar);
      end;
    Sauf erreurs de conversion de ma part :p

    Normalement ce qui suit fonctionne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    MonRecord.Total := PAnsiChar('0123456789');
    Showmessage(MonRecord.UnRecord.Tier2); // Affiche 345
    Showmessage(MonREcord.LEs4Premiers); // affiche 0123
    Showmessage(MonRecord.Moitier2); // affiche 56789
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

  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
    Je te remercie pour tes exemples et explications.


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

Discussions similaires

  1. Manipulation des pointeurs sur des array of record
    Par kracter56 dans le forum Débuter
    Réponses: 8
    Dernier message: 13/04/2012, 09h58
  2. Length : longueur d'un tableau dans pointeur de record
    Par sendibacori dans le forum Ada
    Réponses: 8
    Dernier message: 25/12/2007, 19h55
  3. Problème de pointeurs et de record
    Par supersnail dans le forum Langage
    Réponses: 6
    Dernier message: 31/08/2007, 19h26
  4. Réponses: 15
    Dernier message: 25/06/2007, 09h35
  5. [LG]fichier typé; record et pointeurs
    Par rigel dans le forum Langage
    Réponses: 6
    Dernier message: 12/05/2004, 16h12

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