¿C贸mo puedo pasar una variable de un formulario a otro en C++ Builder 5?
¿C贸mo puedo pasar una variable de un formulario a otro en C++ Builder 5?
Hola
en el formulario uno pones
#include "unit2.h"//el 2° formulario
y donde quieras llamar a la variable pones
Form2->NombreVariable = algo;
eso si la variable tiene que estar declarada en el unit2.h para que sea parte del formulario 2.
Te invito a mi foro
http://ayudacbuilder.foros.st/
Suerte.
en el formulario uno pones
#include "unit2.h"//el 2° formulario
y donde quieras llamar a la variable pones
Form2->NombreVariable = algo;
eso si la variable tiene que estar declarada en el unit2.h para que sea parte del formulario 2.
Te invito a mi foro
http://ayudacbuilder.foros.st/
Suerte.
grrrr, me he liado.
A ver, yo tengo dos formularios: Form1 y Form2.
En Form2 tengo declarada una variable TVariant y cuando yo mando la orden Form2->Hide() necesito que Form1 coja esa variable TVariant.
Espero haberme explicado mejor ahora :D GraciaS!
Ele
A ver, yo tengo dos formularios: Form1 y Form2.
En Form2 tengo declarada una variable TVariant y cuando yo mando la orden Form2->Hide() necesito que Form1 coja esa variable TVariant.
Espero haberme explicado mejor ahora :D GraciaS!
Ele
Vaya... como estoy. Se me ha olvidado aclarar una cosa:
El Form2 lo abro desde Form1 de forma modal. Es decir: Form2->ShowModal()
Eso es todo
El Form2 lo abro desde Form1 de forma modal. Es decir: Form2->ShowModal()
Eso es todo
Esperame almuerzo y te ayudo....
visita mi foro
http://ayudacbuilder.foros.st/
es de programacion en c, c++ y cbuilder.-
;-)
visita mi foro
http://ayudacbuilder.foros.st/
es de programacion en c, c++ y cbuilder.-
;-)
Veamos este seria el Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->ShowModal();
}
//---------------------------------------------------------------------------
Este el Unit2.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form1->Edit1->Text = var;
Hide();
}
//---------------------------------------------------------------------------
y el unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <utilcls.h>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
TVariant var;
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Ojo que si solo haces Form2->Hide() y el form2 fue llamado de forma modal solo lo estas ocultando, por lo que igual el form1 quedaria bloqueado.-
asigne el variant a un edit en el form1 porque no se me ocurrio otra forma....
Suerte!!!!
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->ShowModal();
}
//---------------------------------------------------------------------------
Este el Unit2.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form1->Edit1->Text = var;
Hide();
}
//---------------------------------------------------------------------------
y el unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <utilcls.h>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
TVariant var;
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Ojo que si solo haces Form2->Hide() y el form2 fue llamado de forma modal solo lo estas ocultando, por lo que igual el form1 quedaria bloqueado.-
asigne el variant a un edit en el form1 porque no se me ocurrio otra forma....
Suerte!!!!
