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 :

if imbriqué impossible /!\ string et boolean


Sujet :

Langage Delphi

  1. #1
    Membre habitué Avatar de avogadro
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    412
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 412
    Points : 188
    Points
    188
    Par défaut if imbriqué impossible /!\ string et boolean
    bonjour, mon if ne passe pas et je ne sais pas comment régler ce pb :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    if ( Memo1.Lines.Strings[0] < IntToStr(256)) and (Memo1.Lines.Strings[0] > IntToStr(0))
    and (Memo1.Lines.Strings[1] < IntToStr(256) and (Memo1.Lines.Strings[1] >= IntToStr(0))
    and (Memo1.Lines.Strings[2] < IntToStr(256) and (Memo1.Lines.Strings[2] >= IntToStr(0))
    and (Memo1.Lines.Strings[3] < IntToStr(256) and (Memo1.Lines.Strings[3] > IntToStr(0)) then
    begin
     (Sender as TEdit).Color := clWhite;
     BitBtn1.Enabled := true;
    end
    else
    begin
     (Sender as TEdit).Color := clRed;
     BitBtn1.Enabled := false;
    end;
    et je reçois ces erreurs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    [Erreur] Unit2.pas(662): Types incompatibles : 'String' et 'Boolean'
    [Erreur] Unit2.pas(663): Types incompatibles : 'String' et 'Boolean'
    [Erreur] Unit2.pas(663): Types incompatibles : 'String' et 'Boolean'
    why???

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2003
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2003
    Messages : 560
    Points : 576
    Points
    576
    Par défaut
    Bonjour,


    A prioris il manque des parenthèse fermante (voire les ???)


    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
     
     
    if 
    ( Memo1.Lines.Strings[0] < IntToStr(256)) // OK
    and 
    (Memo1.Lines.Strings[0] > IntToStr(0))  // OK
    and 
    (Memo1.Lines.Strings[1] < IntToStr(256) //  ???
    and 
    (Memo1.Lines.Strings[1] >= IntToStr(0)) // OK
    and 
    (Memo1.Lines.Strings[2] < IntToStr(256) // ???
    and 
    (Memo1.Lines.Strings[2] >= IntToStr(0)) // OK
    and 
    (Memo1.Lines.Strings[3] < IntToStr(256) // ???
    and 
    (Memo1.Lines.Strings[3] > IntToStr(0)) // OK

  3. #3
    Membre expérimenté
    Avatar de Harry
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2002
    Messages
    1 224
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2002
    Messages : 1 224
    Points : 1 331
    Points
    1 331
    Par défaut
    T'as pas oublié des parenthèses à partir de la deuxième ligne ?

    Edit : (Zut grillé par TJF)

  4. #4
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Santé

    Informations forums :
    Inscription : Mai 2002
    Messages : 245
    Points : 154
    Points
    154
    Par défaut
    Tu oublies des parentheses fermantes. Essaie ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
    if ( Memo1.Lines.Strings[0] < IntToStr(256)) and (Memo1.Lines.Strings[0] > IntToStr(0))
    and (Memo1.Lines.Strings[1] < IntToStr(256)) and (Memo1.Lines.Strings[1] >= IntToStr(0))
    and (Memo1.Lines.Strings[2] < IntToStr(256)) and (Memo1.Lines.Strings[2] >= IntToStr(0))
    and (Memo1.Lines.Strings[3] < IntToStr(256)) and (Memo1.Lines.Strings[3] > IntToStr(0)) then
    Edit: Grrr grille deux fois

  5. #5
    Membre habitué Avatar de avogadro
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    412
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 412
    Points : 188
    Points
    188
    Par défaut
    niquel mais mon if a parfois des problème, si par exemple je met 250.5.5.5 il est faux :s

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
          if ( (Memo1.Lines.Strings[0] > IntToStr(0)) and (Memo1.Lines.Strings[0] < IntToStr(256)) ) then
             if ( (Memo1.Lines.Strings[1] >= IntToStr(0)) and (Memo1.Lines.Strings[1] < IntToStr(256)) ) then
                if ( (Memo1.Lines.Strings[2] >= IntToStr(0)) and (Memo1.Lines.Strings[2] < IntToStr(256)) ) then
                  if ( (Memo1.Lines.Strings[3] >= IntToStr(0)) and (Memo1.Lines.Strings[3] < IntToStr(256)) ) then
          begin
            (Sender as TEdit).Color := clWhite;
            BitBtn1.Enabled := true;
          end
          else
          begin
            (Sender as TEdit).Color := clRed;
            BitBtn1.Enabled := false;
          end;
         end;
    de même avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if ( Memo1.Lines.Strings[0] < IntToStr(256)) and (Memo1.Lines.Strings[0] > IntToStr(0))
    and (Memo1.Lines.Strings[1] < IntToStr(256)) and (Memo1.Lines.Strings[1] >= IntToStr(0))
    and (Memo1.Lines.Strings[2] < IntToStr(256)) and (Memo1.Lines.Strings[2] >= IntToStr(0))
    and (Memo1.Lines.Strings[3] < IntToStr(256)) and (Memo1.Lines.Strings[3] > IntToStr(0)) then

  6. #6
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 875
    Points : 11 365
    Points
    11 365
    Billets dans le blog
    6
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    with Memo1 do
     if ( StrToInt(Lines[0]) in [1..255] )
     and ( StrToInt(Lines[1]) in [0..255] )
     and ( StrToInt(Lines[2]) in [0..255] )
     and ( StrToInt(Lines[3]) in [0..255] )
     then begin
       (Sender as TEdit).Color := clWhite;
       BitBtn1.Enabled := true;
     end
     else begin
       (Sender as TEdit).Color := clRed;
       BitBtn1.Enabled := false;
     end;
    pour faire moins de conversions (si on n'est pas sûr d'avoir des entiers, utiliser StrToIntDef ou TryStrToIntDef avec -1 comme valeur par défaut, pour ne pas vérifier la condition)

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

Discussions similaires

  1. [Maths] Evaluation String en Boolean
    Par D-NiM dans le forum API standards et tierces
    Réponses: 12
    Dernier message: 26/06/2007, 06h56
  2. Template imbriqué impossible
    Par topgif49 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 19/04/2006, 13h48
  3. [XPATH] Impossible de convertir #BOOLEAN en un NodeList
    Par claudyyyyy dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 08/02/2006, 16h00
  4. Réponses: 4
    Dernier message: 04/08/2005, 08h23
  5. Comment convertir une string en boolean ?
    Par olivier12345600 dans le forum Langage
    Réponses: 6
    Dernier message: 25/06/2005, 15h54

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