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