954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do I pass values from a called form to a calling forms variables?

I am relatively new to Borland 2006 C++ Builder. I have a form which has about 6 buttons and a text box for selecting and inputting values respectively (e.g. Clicking on Button 1 should return "100" to a variable in the calling form. Likewise, entering 100 into the text box and pressing enter would do same. I have been able to return values from the text box e.g.

String amt = frmChoice->TxtBxt1->Text

However, I need help on how to return values to the calling forms variable when a user clicks one of the buttons instead of entering text in the text box.
Thanks in advance.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

That sounds like the kind of situation where you would raise an event and pass the data as an argument to the event.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thanks for your help Narue. Since I am closing the called form with the code

this->close()


once one of the buttons is clicked or the OK button is used to pass the text typed in the input box,
can I assign the appropraite value to a variable that has a visibility within the whole called form in all the buttonclick events and then pass the value within the variable in the OnClose() event of the called Form?
Thanks.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

Yes, you can do it that way if you want. I don't think it's the best solution, but I get the feeling you don't want to follow my advice since you completely ignored my last post.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

I'm sorry about that. I got what you said as per raising an event but I don't really know the specific one to raise.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

>I don't really know the specific one to raise.
The event is raised when you click the button. You need to handle that event in the calling form. Your documentation should cover how to do this in detail.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Please let me know which event to raise and how to raise it. Thank you.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

I'm using Borland 2006 C++ Builder Win32 environment. The documentation only says something about .NET while its silent about Win32.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

Are you actually using the Win32 API to do this? You were talking about forms, so I gathered that you were using Windows Forms, which is .NET. Maybe you should post your code.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Yes, I am using WinForms on a Win32 development platform. The code for the calling form is as follows:

void __fastcall TfrmClient::btnRechargeClick(TObject *Sender)
{
 // Increment Transaction Number
 transaction_no++;
 frmAmountSelector->Show(); 
// *** where I got stuck trying to pass c_amt from the other form***

The code above loads the form which allows the user to click a button to select the desired amount.

The code below is that of the called form.

void __fastcall TfrmAmountSelector::btn100Click(TObject *Sender)
{
  c_amt = "100";
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAmountSelector::btn200Click(TObject *Sender)
{
  c_amt = "200";
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAmountSelector::btn500Click(TObject *Sender)
{
  c_amt = "500";
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAmountSelector::btn1000Click(TObject *Sender)
{
  c_amt = "1000";
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAmountSelector::btn2000Click(TObject *Sender)
{
  c_amt = "2000";
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAmountSelector::btn5000Click(TObject *Sender)
{
  c_amt = "5000";
 this->Close();
}


c_amt is a global variable within the called form.
Thanks. I really appreciate your help.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

Could you post the declaration of TfrmAmountSelector and TfrmClient please.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Thanks for the help. I've decided to declare c_amt as a public variable within TFrmAmountSelector and then access its values from TFrmClient using

TFrmAmountSelector->c_amt


. Thanks.

tunday
Newbie Poster
18 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You