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 :

Over Stack error


Sujet :

Langage Delphi

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Over Stack error
    Bonjour,

    Dans ma form principale je fais les déclarations suivantes :
    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
    const
      MaxPixelCount = 65536;
    type
      TSegment = record
        Num : Integer;
        Code : String[4];
        LMin,LMax,CMin,CMax,hMin,hMax: single;
        NbPix: integer;
        PerCent: single;
        LMean,CMean,hMean: single;
        Color: TColor;
      end;
      TSeg5x5x36= array[0..799] of TSegment;
      RGBTripleArray = array[0..MaxPixelCount-1] of TRGBTriple;
      pRGBTripleArray = ^RGBTripleArray;
      TMainForm = class(TForm)
    Sans déclaration supplémentaire dans OnCreate pas de problème.
    Mais dés que j'initialise la structure tableau TSeg5x5x36 dans CreateForm je provoque une Over Stack error.
    J'ai donc essayé de tracer le problème en éditant un fichier texte lors de l'initialisation du tableau avec le code suivant :
    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
      AssignFile(F,'TextFile.txt');
      Rewrite(F);
        I:= 0;
        for L := 0 to 4 do
          for C := 0 to 4 do
            for H := 0 to 35 do
              begin
      S:= '';
                fillChar(CurSeg[I],Sizeof(TSegment),#0);
                CurSeg[I].Num := I;
      S:= S+IntToStr(I)+#9;
                CurSeg[I].Code:= IntToStr(L)+IntToStr(C)+
                                  Tools_LeftJustifyZero(IntToStr(H),2);
      S:= S+CurSeg[I].Code+#9;
                CurSeg[I].LMin:= L*20;
      S:= S+FloatToStrF(CurSeg[I].LMin,ffFixed,5,0)+#9;
                CurSeg[I].LMax:= Succ(L)*20;
      S:= S+FloatToStrF(CurSeg[I].LMax,ffFixed,5,0)+#9;;
                CurSeg[I].CMin:= C*20;
      S:= S+FloatToStrF(CurSeg[I].CMin,ffFixed,5,0)+#9;
                CurSeg[I].CMax:= Succ(C)*20;
      S:= S+FloatToStrF(CurSeg[I].CMax,ffFixed,5,0)+#9;
                CurSeg[I].hMin:= H*10;
      S:= S+FloatToStrF(CurSeg[I].HMin,ffFixed,5,0)+#9;
                CurSeg[I].hMax:= 10+H*10;
      S:= S+FloatToStrF(CurSeg[I].HMax,ffFixed,5,0);
      WriteLn(F,S);
                Inc(I);
              end;
      CloseFile(F);
    L'erreur OverFlow apparait édition du fichier texte ou pas.
    Dès la première ligne du fichier texte je constate une anomalie sur la dernière colonne du tableau
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    0	0000	0	20	0	20	0	1E2	
    1	0001	0	20	0	20	10	1.1E2	
    2	0002	0	20	0	20	20	1.2E2	
    3	0003	0	20	0	20	30	1.3E2	
    4	0004	0	20	0	20	40	1.4E2	
    5	0005	0	20	0	20	50	1.5E2	
    6	0006	0	20	0	20	60	1.6E2	
    7	0007	0	20	0	20	70	1.7E2	
    8	0008	0	20	0	20	80	1.8E2	
    9	0009	0	20	0	20	90	1.9E2
    et de surcroît le tableau devrait comprendre 899 lignes et il s'arrête à la 896ème !!!

    Quelqu'un peut-il venir à mon secours ?

  2. #2
    Membre chevronné Avatar de philnext
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    1 552
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 552
    Points : 1 780
    Points
    1 780
    Par défaut
    Je ne vois pas où est le code de l'initialisation qui te déclenche l'erreur.

  3. #3
    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
    5 x 5 x 36 = 900 et non 799 !

    Code est mieux si stocké en Word, plus facile à comparer/manipuler, plus performant et si tu veux stocker les TSegment dans un Stream ce sera plus simple à gérer.


    Packed ! histoire d’aligner les tableaux et records

    Format et TStringList plutôt que les imbuvables suites de Int/FloatToStr et utilisations aberrante en 2013 de AssignFile, Reset/Rewrite, CloseFile,

    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
      TSegment = packed record
        Num     : Integer;
        Code    : word; // Word ! min = 1101 max = 5536
        LMin,
        LMax,
        CMin,
        CMax,
        hMin,
        hMax    : single;
        NbPix   : integer;
        PerCent : single;
        LMean,
        CMean,
        hMean   : single;
        Color   : TColor;
      end;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
      TSeg5x5x36 = packed array[0..(5*5*36)-1] of TSegment;
     
      RGBTripleArray  = packed array[0..0] of TRGBTriple; // like PChar !
      pRGBTripleArray = ^RGBTripleArray;
    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
    46
    47
    48
    49
    50
    51
    52
     
    procedure TFormX.FormCreate(Sender: TObject);
    var I,L,C,H: integer;
        CurSeg : TSeg5x5x36;
    begin
      with TStringList.Create do
      try
        I := 0;
     
        fillChar(CurSeg, Length(CurSeg)*SizeOf(TSegment), 0);
     
        for L := 0 to 4 do
          for C := 0 to 4 do
            for H := 0 to 35 do
            begin
              CurSeg[I].Num := I;
              CurSeg[I].Code:= (L+1)*1000+(C+1)*100+(H+1);
              CurSeg[I].LMin:= L * 20;
              CurSeg[I].LMax:= Succ(L) * 20;
              CurSeg[I].CMin:= C * 20;
              CurSeg[I].CMax:= Succ(C) * 20;
              CurSeg[I].hMin:= H * 10;
              CurSeg[I].hMax:= 10 + H * 10;
     
              add( format('%.3d'+#9+ // 000..900
                          '%.4d'+#9+ // 1101..5536
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f',
                   [ I,
                     CurSeg[I].Code,
                     CurSeg[I].LMin,
                     CurSeg[I].LMax,
                     CurSeg[I].CMin,
                     CurSeg[I].CMax,
                     CurSeg[I].HMin,
                     CurSeg[I].HMax
                   ]));
     
                Inc(I);
              end;
     
        SaveToFile(ExtractFilePath(ParamStr(0))+ 'TextFile.txt');
      finally
        Free;
      end;
    end;
     
    end.

    Le fichier rendus (extrait des 30 premières lignes) :
    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
     
    000	1101	0.00000	20.00000	0.00000	20.00000	0.00000	10.00000
    001	1102	0.00000	20.00000	0.00000	20.00000	10.00000	20.00000
    002	1103	0.00000	20.00000	0.00000	20.00000	20.00000	30.00000
    003	1104	0.00000	20.00000	0.00000	20.00000	30.00000	40.00000
    004	1105	0.00000	20.00000	0.00000	20.00000	40.00000	50.00000
    005	1106	0.00000	20.00000	0.00000	20.00000	50.00000	60.00000
    006	1107	0.00000	20.00000	0.00000	20.00000	60.00000	70.00000
    007	1108	0.00000	20.00000	0.00000	20.00000	70.00000	80.00000
    008	1109	0.00000	20.00000	0.00000	20.00000	80.00000	90.00000
    009	1110	0.00000	20.00000	0.00000	20.00000	90.00000	100.00000
    010	1111	0.00000	20.00000	0.00000	20.00000	100.00000	110.00000
    011	1112	0.00000	20.00000	0.00000	20.00000	110.00000	120.00000
    012	1113	0.00000	20.00000	0.00000	20.00000	120.00000	130.00000
    013	1114	0.00000	20.00000	0.00000	20.00000	130.00000	140.00000
    014	1115	0.00000	20.00000	0.00000	20.00000	140.00000	150.00000
    015	1116	0.00000	20.00000	0.00000	20.00000	150.00000	160.00000
    016	1117	0.00000	20.00000	0.00000	20.00000	160.00000	170.00000
    017	1118	0.00000	20.00000	0.00000	20.00000	170.00000	180.00000
    018	1119	0.00000	20.00000	0.00000	20.00000	180.00000	190.00000
    019	1120	0.00000	20.00000	0.00000	20.00000	190.00000	200.00000
    020	1121	0.00000	20.00000	0.00000	20.00000	200.00000	210.00000
    021	1122	0.00000	20.00000	0.00000	20.00000	210.00000	220.00000
    022	1123	0.00000	20.00000	0.00000	20.00000	220.00000	230.00000
    023	1124	0.00000	20.00000	0.00000	20.00000	230.00000	240.00000
    024	1125	0.00000	20.00000	0.00000	20.00000	240.00000	250.00000
    025	1126	0.00000	20.00000	0.00000	20.00000	250.00000	260.00000
    026	1127	0.00000	20.00000	0.00000	20.00000	260.00000	270.00000
    027	1128	0.00000	20.00000	0.00000	20.00000	270.00000	280.00000
    028	1129	0.00000	20.00000	0.00000	20.00000	280.00000	290.00000
    029	1130	0.00000	20.00000	0.00000	20.00000	290.00000	300.00000
    030	1131	0.00000	20.00000	0.00000	20.00000	300.00000	310.00000

  4. #4
    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
    Single n'est pas justifié partout apparement :

    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
     
      TSegment = packed record
        Num     : Integer;
        Code    : word; // Word ! min = 1101 max = 5536
        LMin,
        LMax,
        CMin,
        CMax,
        hMin,
        hMax,
        NbPix   : integer;
        PerCent : single;
        LMean,
        CMean,
        hMean   : single;
        Color   : TColor;
      end;
    Une variante pour te montrer les possibilité de souplesses :

    type TSeg5x5x36 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
      TSeg5x5x36 = packed record
        case integer of
          0:(LCH: array[0..4,0..4,0..35] of TSegment);
          1:(I  : array[0..5*5*36-1] of TSegment);
      end;
    Init et remplissage :

    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
    var L,C,H: integer;
        CurSeg : TSeg5x5x36;
    begin
      with TStringList.Create do
      try
     
        fillChar(CurSeg, Length(CurSeg.I)*SizeOf(TSegment), 0);
     
        for L := 0 to 4 do
          for C := 0 to 4 do
            for H := 0 to 35 do
            begin
              with CurSeg.LCH[L, C, H] do
              begin
                Num :=  H + (36 * C) + (180*L); // 0..899
                Code:= L*1000+C*100+H; // 0000..4435
                LMin:= L * 20;
                LMax:= (L+1) * 20;
                CMin:= C * 20;
                CMax:= (C+1) * 20;
                hMin:= H * 10;
                hMax:= 10 + H * 10;
     
                add(
                  format(
                    '%.3d'+#9+ '%.4d'+#9+ '%d'+#9+ '%d'+#9+ '%d'+#9+ '%d'+#9+ '%d'+#9+ '%d',
                  [  Num,       Code,      LMin,    LMax,    CMin,    CMax,    HMin,    HMax
                  ])
                );
              end;
            end;
        SaveToFile(ExtractFilePath(ParamStr(0))+ 'TextFile.txt');
      finally
        Free;
      end;
    end;

    Fichier 2 fois moins gros (59Ko -> 26Ko)
    Génération 2 fois plus rapide.

    Extrait :
    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
     
    000	1101	0	20	0	20	0	10
    001	1102	0	20	0	20	10	20
    002	1103	0	20	0	20	20	30
    003	1104	0	20	0	20	30	40
    004	1105	0	20	0	20	40	50
    005	1106	0	20	0	20	50	60
    006	1107	0	20	0	20	60	70
    007	1108	0	20	0	20	70	80
    008	1109	0	20	0	20	80	90
    009	1110	0	20	0	20	90	100
    010	1111	0	20	0	20	100	110
    011	1112	0	20	0	20	110	120
    012	1113	0	20	0	20	120	130
    013	1114	0	20	0	20	130	140
    014	1115	0	20	0	20	140	150
    015	1116	0	20	0	20	150	160
    016	1117	0	20	0	20	160	170
    017	1118	0	20	0	20	170	180
    018	1119	0	20	0	20	180	190
    019	1120	0	20	0	20	190	200
    020	1121	0	20	0	20	200	210
    021	1122	0	20	0	20	210	220
    022	1123	0	20	0	20	220	230
    023	1124	0	20	0	20	230	240
    024	1125	0	20	0	20	240	250
    025	1126	0	20	0	20	250	260
    026	1127	0	20	0	20	260	270
    027	1128	0	20	0	20	270	280
    028	1129	0	20	0	20	280	290
    029	1130	0	20	0	20	290	300

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Merci mais gros problème !!!
    J'ai réécrit le code comme conseillé mais delphi ne reconnait pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
              add( format('%.3d'+#9+ // 000..900
                          '%.4d'+#9+ // 1101..5536
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f'+#9+
                          '%.5f',
    il m'adresse un message d'erreur de format à cause de %.3d
    J'essaie de corriger avec les formats plus traditionnels

  6. #6
    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
    quel version de Delphi as tu ?

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut
    Delphi 2007

  8. #8
    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
    Tu as changer la structure de TSegment ou pas ?
    qu'est-ce qu'il t'affiche comme erreur ?

  9. #9
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut
    Je n'avais pas changé Tsegment et l'erreur qui s'affichait était de mémoire "format %3.d incompatible"
    Mais depuis pour évitre cette erreur j'ai rétabli le champ code en string[4] car je souhaite que le code démarre à "0000" et j'ai modifié l'initialisation de la stringlist telle que :
    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
        with TStringList.Create do
        try
          I := 0;
          fillChar(CurSeg, Length(CurSeg)*SizeOf(TSegment), 0);
          add( 'Num Code LMin LMax CMin CMax HMin HMax ');
          for L := 0 to 4 do
            for C := 0 to 4 do
              for H := 0 to 35 do
              begin
                CurSeg[I].Num := I;
                CurSeg[I].Code:= IntToStr(L)+IntToStr(C)+Tools_LeftJustifyZero(IntToStr(H),2);
                CurSeg[I].LMin:= L * 20;
                CurSeg[I].LMax:= Succ(L) * 20;
                CurSeg[I].CMin:= C * 20;
                CurSeg[I].CMax:= Succ(C) * 20;
                CurSeg[I].hMin:= H * 10;
                CurSeg[I].hMax:= 10 + H * 10;
                add( IntToStr(I)+#9+CurSeg[I].Code+#9+
                    FloatToStrF(CurSeg[I].LMin,ffFixed,5,0)+#9+
                    FloatToStrF(CurSeg[I].LMax,ffFixed,5,0)+#9+
                    FloatToStrF(CurSeg[I].CMin,ffFixed,5,0)+#9+
                    FloatToStrF(CurSeg[I].CMax,ffFixed,5,0)+#9+
                    FloatToStrF(CurSeg[I].HMin,ffFixed,5,0)+#9+
                    FloatToStrF(CurSeg[I].HMax,ffFixed,5,0));
                Inc(I);
              end;
          SaveToFile('TextFile.txt');
          finally
            Free;
          end;
        end;
    Je n'ai plus d'erreur et le fichier TextFile.Txt débute par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Num Code LMin LMax CMin CMax HMin HMax 
    0	0000	0	20	0	20	0	10
    1	0001	0	20	0	20	10	20
    2	0002	0	20	0	20	20	30
    3	0003	0	20	0	20	30	40
    4	0004	0	20	0	20	40	50
    5	0005	0	20	0	20	50	60
    6	0006	0	20	0	20	60	70
    7	0007	0	20	0	20	70	80
    8	0008	0	20	0	20	80	90
    9	0009	0	20	0	20	90	100
    et se termine correctement au 899ème segment.

    Peux-tu m'expliquer ce qui générait l'erreur "over stack" dans la première version du code car je n'ai pas compris pourquoi.

    Mille merci, car j'ai été dépané.

  10. #10
    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
    ton tableau contenais 800 élément et pas 900.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TSeg5x5x36= array[0..799] of TSegment;
    donc arrivé au 800eme ... paf dans les dents !

    d'ou la déclaration de du high en 5*5*36-1 plutôt qu'une valeur fixe.


    de plus je maintient que tu devrais mettre code en word et le calculer comme ça :

    soit de 0000 à 4435 avec un format '%.4d' pour avoir les zéro en texte.

    Ce sera plus rapide si tu dois filtrer cette valeur plus tard sans passer par des IntToStr et StrToInt imbuvables.

    Ce sera source d’embêtement si tu laisse en string et que tu passe en Unicode ou quand tu cherchera a enregistrer des TSegments dans un Stream.

  11. #11
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut
    Merci pour toutes ces explications, mais

    1 - Delphi 2007win32 comment utiliser le format '%.4d' et est-ce possible ?
    2 - A partir de quelle version Delphi accepte ce format ? Je possède RAD Studio XE mais ne l'ai pas installé car il fallait mettre à jour toutes les anciennes sources.

    Bonne journée

  12. #12
    Membre expert
    Avatar de Charly910
    Homme Profil pro
    Ingénieur TP
    Inscrit en
    Décembre 2006
    Messages
    2 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur TP
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 374
    Points : 3 150
    Points
    3 150
    Par défaut
    Bonjour,

    le format '%.4d' existe dans D7 donc il doit aussi exister dans Delphi2007 (que je ne connais pas) - cela fonctionne aussi dans mon XE2

    A+

    Charly

  13. #13
    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
    Tiens regarde sur l'aide que j'avais fait pour format :

    http://deefaze.ftp-developpez.com/de...ion-format.pdf

    "d" c'est pour les entiers, byte, smallint, integer, word, etc.
    "f" c'est pour les flottants, single, extended, double
    "s" c'est pour les chaines, string, char

    format existe depuis TurboPascal si je ne m'abuse.

  14. #14
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Ok et Merci
    Ok je viens de faire l'essai suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    var
      D: Word;
    begin
      D:= 0;
      ShowMessage(format('mon chiffre est : %.4d', [D]));
    J'obtiens bien l'affichage "0000". Je vais donc placer un Word à la place de String dans le champ Code du record TSegment et pour les floats je vais supprimer les FloatToStrF et les remplacer par format('%.2, [MonFloat]);

    Je vais tenter cette modif...

  15. #15
    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
    '%.2f' pour les flottants !

    % -> dit au compilateur, attention voila un symbole de formatage
    .2 -> formate sur 2 caractère minimum (0 si chiffre ou espace si chaine)
    F ou D ou X ou P -> type de formatage, erreur si ne correspond pas à l'élement (identique a une erreur de conversion avec IntToStr ou FloatToStr)


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    '%.2f',[pi] -> 3.14
    '%.4f',[pi] -> 3.1415
    '%d',[pi] -> erreur
    '%.4d',[round(pi)] -> 0003
    '%d %d',[width, height] -> 640 480
    '%.2f%%',[width/height*100] -> 133.33%

Discussions similaires

  1. ModernCv : \href dans \homepage stack error
    Par nostroyo dans le forum Débuter
    Réponses: 2
    Dernier message: 09/03/2015, 10h21
  2. Stack Overflow Error
    Par bousnguar dans le forum JSF
    Réponses: 5
    Dernier message: 11/08/2008, 11h28
  3. CXX0069: Error: variable needs stack frame
    Par stof dans le forum Visual C++
    Réponses: 7
    Dernier message: 22/07/2008, 17h41
  4. [TP] Error stack over flow 202
    Par Full62fr dans le forum Turbo Pascal
    Réponses: 2
    Dernier message: 05/02/2008, 17h34
  5. Error Stack OverFlow
    Par fabred dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 14/05/2007, 13h54

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