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 :

Problème avec StrToInt


Sujet :

Delphi

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

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut Problème avec StrToInt
    Bonjour,
    Vous allez probablement me trouver très nul, mais voici une procédure:
    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
    procedure GetSubsonicStepDistance;
    var
      intIndex,
      intDiff,
      intDepDist,
      intCumDist: Integer;
    begin
      with frmTripPlanner do
      begin
        intDepDist:= StrToInt(edSubDepDist.Text);
        intIndex:= cbxDepWp.ItemIndex;
        intCumDist:= StrToInt(GstlWPDist[intIndex]);
        intDiff:= StrToInt(GstlWPDist[intIndex + 1])
                - StrToInt(GstlWPDist[intIndex]);
        GintDepProtectDist:= intDepDist;
        while intDepDist >= intDiff do
        begin
          intDepDist:= intDepDist - intDiff;
          Inc(intIndex);
          cbxDepWp.ItemIndex:= intIndex;
          intCumDist:= StrToInt(GstlWPDist[intIndex]);
          edSubDepDist.Text:= IntToStr(intDepDist);
          GintDepProtectDist:= intDepDist + intCumDist;
          intDiff:= StrToInt(GstlWPDist[intIndex + 1])
                  - StrToInt(GstlWPDist[intIndex]);
        end;
        lblTotalDepStep.Caption:= 'Total Depart. Distance: '
                                  + IntToStr(GintDepProtectDist) + ' NM';
      end;
    end;
    Dans la quelle, alors que :
    Contient : '51',
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     intCumDist:= StrToInt(GstlWPDist[intIndex]);
    Est égal à 0.

    Une explication?

    Cordialement
    Pierre

    Cordialement

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 447
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 447
    Points : 24 849
    Points
    24 849
    Par défaut
    Sans savoir ce qu'il y a réellement dans GstlWPDist, difficile de répondre
    Es-tu sûr que intIndex soit bon ?
    GstlWPDist est un array of string, une TStringList ?
    Avec un tableau, tu peux lire en dehors, avec une TStringList cela provoque une exception
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    merci de votre réponse,

    GstWPDist est une TStringList.
    La TStringlList contient
    0
    51
    177
    370
    435
    713
    903
    1284
    ...
    3310


    intIndex est correct (1) et la Chaine lue dans la TStringList est '51'.

    Cordialement
    Pierre

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Bonjour,

    Le problème est résolu, sans que je puisse expliquer pourquoi.
    J'ai modifié le code donné dans le premier post en :
    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
    procedure GetSubsonicStepDistance;
    var
      intIndex,
      intDiff,
      intDepDist: Integer;
      intCumDist : Integer;
    begin
      intDepDist:= StrToInt(edSubDepDist.Text);
      intIndex:= cbxDepWp.ItemIndex;
      intCumDist:= StrToInt(GstlWPDist[intIndex]);
      intDiff:= StrToInt(GstlWPDist[intIndex + 1])
              - StrToInt(GstlWPDist[intIndex]);
      GintDepProtectDist:= intDepDist + intCumDist;
      while intDepDist >= intDiff do
      begin
        intDepDist:= intDepDist - intDiff;
        Inc(intIndex);
        cbxDepWp.ItemIndex:= intIndex;
        intCumDist:= StrToInt(GstlWPDist[intIndex]);
        edSubDepDist.Text:= IntToStr(intDepDist);
        GintDepProtectDist:= intDepDist + intCumDist;
        intDiff:= StrToInt(GstlWPDist[intIndex + 1])
                - StrToInt(GstlWPDist[intIndex]);
      end;
      lblTotalDepStep.Caption:= 'Total Depart. Distance: '
                                + IntToStr(GintDepProtectDist) + ' NM';
    end;
    Et tout fonctionne parfaitement.

    merci de votre temps.

    Cordialement
    Pierre

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

Discussions similaires

  1. VC++ Direct3D8, problème avec LPD3DXFONT et LPD3DTEXTURE8
    Par Magus (Dave) dans le forum DirectX
    Réponses: 3
    Dernier message: 03/08/2002, 11h10
  2. Problème avec [b]struct[/b]
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 2
    Dernier message: 17/07/2002, 10h25
  3. Problème avec le type 'Corba::Any_out'
    Par Steven dans le forum CORBA
    Réponses: 2
    Dernier message: 14/07/2002, 18h48
  4. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10

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