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

C++Builder Discussion :

passage de variables entre unites [Langage/Algorithme]


Sujet :

C++Builder

  1. #1
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut passage de variables entre unites
    Bonjours
    J'ai deux problemes que je n'arrive pas a solutionner sur une Form j'ai trois TButtons trois TLabels, puis j'ai fais nouveau->unit, par programme je fais passer des variables d'une unite a l'autre, cela fonctionne mais j'ai des warning, les codes
    unit1.cpp
    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
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
    {
    // Lien <a href="http://www.developpez.net/forums/d432371/c-cpp/outils-c-cpp/cppbuilder/declaration-variable-global/" target="_blank">http://www.developpez.net/forums/d43...riable-global/</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    teste(a);
    Label1->Caption = a;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    b = "ici : ";
    essai(b);
    Label2->Caption = b;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
    c = 10;
    calcul(c);
    Label3->Caption = c;
    }
    //---------------------------------------------------------------------------
    unit1.h
    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
     
    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
         TButton *Button1;
         TLabel *Label1;
         TButton *Button2;
         TLabel *Label2;
         TButton *Button3;
         TLabel *Label3;
         void __fastcall Button1Click(TObject *Sender);
         void __fastcall Button2Click(TObject *Sender);
         void __fastcall Button3Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
         __fastcall TForm1(TComponent* Owner);
         String a;
         String b;
         int c;
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
         teste(String a);
         essai(String b);
         calcul(int c);
    //---------------------------------------------------------------------------
    #endif
    unit2.cpp
    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
     
    //---------------------------------------------------------------------------
    #pragma hdrstop
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    //======================
    teste(String a)
    {
    Form1->a = "toto";
    }
    //======================
    essai(String b)
    {
    Form1->b = b + "titi";
    }
    //======================
    calcul(int c)
    {
    Form1->c = c * 3;
    }
    le code fonctionne j'ai bien le passage des variables mais sur les lignes teste(String a), essai(String b), calcul(int c), j'ai un warning
    [C++ Warning] File1.cpp(7): W8070 Function should return a value
    y a t'il quelque chose a faire pour empecher ces messages sans les annuler dans le debugger
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  2. #2
    Membre chevronné
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Points : 2 189
    Points
    2 189
    Par défaut
    Citation Envoyé par blondelle Voir le message
    unit2.cpp
    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
     
    //---------------------------------------------------------------------------
    #pragma hdrstop
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    //======================
    teste(String a)
    {
    Form1->a = "toto";
    }
    //======================
    essai(String b)
    {
    Form1->b = b + "titi";
    }
    //======================
    calcul(int c)
    {
    Form1->c = c * 3;
    }
    le code fonctionne j'ai bien le passage des variables mais sur les lignes teste(String a), essai(String b), calcul(int c), j'ai un warning
    [C++ Warning] File1.cpp(7): W8070 Function should return a value
    y a t'il quelque chose a faire pour empecher ces messages sans les annuler dans le debugger
    Il manque pas les void devant tes fonctions.

    PS: j'ai regarder le post très rapidement!
    • Plus un ordinateur possède de RAM, plus vite il peut générer un message d'erreur. - Dave Barry
    • Je n'ai pas peur des ordinateurs. J'ai peur qu'ils viennent à nous manquer. - Isaac Asimov
    • Le code source est comme une belle femme, plus on le regarde, plus on trouve des défauts. - Crayon

  3. #3
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci Crayon pour ta reponse
    Si je met les void ca me dit que la variable que je passe n'est pas definie, sauf erreur de ma part
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  4. #4
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Hello
    il me semble comme l'a dit Crayon qu'il manque les déclarations de type
    (void en l'occurence) dans la déclaration
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    void teste(String a);
    void essai(String b);
    void calcul(int c);
    et également dans l'implémentation
    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
     
    void teste(String a)
    {
    Form1->a = "toto";
    }
    //======================
    void essai(String b)
    {
    Form1->b = b + "titi";
    }
    //======================
    void calcul(int c)
    {
    Form1->c = c * 3;
    }
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  5. #5
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci DjmSoftware
    Les void places aux bons endroit cela fonctionne mieux, je n'ai plus de warning, voici le code corrige
    Unit1.cpp
    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
     
    #include "Unit1.h"
    #include "Unit2.h"
    #include "File1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
    {
    // Lien <a href="http://www.developpez.net/forums/d432371/c-cpp/outils-c-cpp/cppbuilder/declaration-variable-global/" target="_blank">http://www.developpez.net/forums/d43...riable-global/</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    void teste(a);
    Label1->Caption = a;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    b = "ici : ";
    essai(b);
    Label2->Caption = b;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
    c = 10;
    calcul(c);
    Label3->Caption = c;
    }
    //---------------------------------------------------------------------------
    Unit1.h
    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
     
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
         TButton *Button1;
         TLabel *Label1;
         TButton *Button2;
         TLabel *Label2;
         TButton *Button3;
         TLabel *Label3;
         void __fastcall Button1Click(TObject *Sender);
         void __fastcall Button2Click(TObject *Sender);
         void __fastcall Button3Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
         __fastcall TForm1(TComponent* Owner);
         String a;
         String b;
         int c;
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
         void teste(String a);
         void essai(String b);
         void calcul(int c);
    //---------------------------------------------------------------------------
    #endif
    Unit2.cpp
    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
     
    #pragma hdrstop
    #include "Unit1.h"
    #include "Unit2.h"
    #include "File1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    //======================
    void teste(String a)
    {
    Form1->a = "toto";
    }
    //======================
    void essai(String b)
    {
    Form1->b = b + "titi";
    }
    //======================
    void calcul(int c)
    {
    Form1->c = c * 3;
    }
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

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

Discussions similaires

  1. [Lazarus] [Linux] Passage de variable entre unités
    Par ovni76 dans le forum Lazarus
    Réponses: 7
    Dernier message: 01/10/2009, 19h34
  2. passage de variable entre jsp ?
    Par MAJIK_ENIS dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 14/04/2006, 11h54
  3. Réponses: 2
    Dernier message: 15/12/2005, 08h43
  4. [C#] Passage de variables entre 2 forms
    Par Tips dans le forum C#
    Réponses: 6
    Dernier message: 06/12/2005, 16h48
  5. [langage] Probleme passage de variables entre modules
    Par Ludo167 dans le forum Langage
    Réponses: 4
    Dernier message: 13/08/2004, 12h25

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