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

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #1
Jun 11th, 2007
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.
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,608
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #2
Jun 11th, 2007
That sounds like the kind of situation where you would raise an event and pass the data as an argument to the event.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #3
Jun 11th, 2007
Thanks for your help Narue. Since I am closing the called form with the code
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,608
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #4
Jun 11th, 2007
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 here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #5
Jun 11th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,608
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #6
Jun 11th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #7
Jun 11th, 2007
Please let me know which event to raise and how to raise it. Thank you.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #8
Jun 11th, 2007
I'm using Borland 2006 C++ Builder Win32 environment. The documentation only says something about .NET while its silent about Win32.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,608
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #9
Jun 11th, 2007
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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: tunday is an unknown quantity at this point 
Solved Threads: 0
tunday tunday is offline Offline
Newbie Poster

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

 
0
  #10
Jun 11th, 2007
Yes, I am using WinForms on a Win32 development platform. The code for the calling form is as follows:

  1. void __fastcall TfrmClient::btnRechargeClick(TObject *Sender)
  2. {
  3. // Increment Transaction Number
  4. transaction_no++;
  5. frmAmountSelector->Show();
  6. // *** 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.
  1. void __fastcall TfrmAmountSelector::btn100Click(TObject *Sender)
  2. {
  3. c_amt = "100";
  4. this->Close();
  5. }
  6. //---------------------------------------------------------------------------
  7. void __fastcall TfrmAmountSelector::btn200Click(TObject *Sender)
  8. {
  9. c_amt = "200";
  10. this->Close();
  11. }
  12. //---------------------------------------------------------------------------
  13. void __fastcall TfrmAmountSelector::btn500Click(TObject *Sender)
  14. {
  15. c_amt = "500";
  16. this->Close();
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TfrmAmountSelector::btn1000Click(TObject *Sender)
  20. {
  21. c_amt = "1000";
  22. this->Close();
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TfrmAmountSelector::btn2000Click(TObject *Sender)
  26. {
  27. c_amt = "2000";
  28. this->Close();
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TfrmAmountSelector::btn5000Click(TObject *Sender)
  32. {
  33. c_amt = "5000";
  34. this->Close();
  35. }

c_amt is a global variable within the called form.
Thanks. I really appreciate your help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC