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.

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

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.

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.

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.

>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.

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

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

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.

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.

Could you post the declaration of TfrmAmountSelector and TfrmClient please.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.