Let's see if I can explain this without mudding everything up. Normally, when you create a form, Builder creates the header and source with the form info set up. For example, suppose you create a form with the name of
MyNewForm. Builder creates in the header:
Code:
public: // User declarations
__fastcall TMyNewForm(TComponent* Owner);
while in the source code it creates
Code:
//---------------------------------------------------------------------------
__fastcall TMyNewForm::TMyNewForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Of course, more lines than these are created but these are the ones you need to know about for this discussion.
Now suppose you want to send an integer and an ansistring to the new form from the calling form. First, change the header by adding a new form declaration that uses the integer and string.
Code:
public: // User declarations
__fastcall TMyNewForm(TComponent* Owner);
__fastcall TMyNewForm(int ANumberInt, AnsiString AStringStr, TComponent* Owner); // I added this line
In the source code, you will need to add:
Code:
__fastcall TMyNewForm::TMyNewForm(int ANumberInt, AnsiString AStringStr, TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
So far so good. Now you need to get those new variables into your code. I do this by declaring a couple of global variables in the
private section of the class in the header. This is found just above the
public section you just modifed. I would put something like:
Code:
private: // User declarations
AnsiString MAStringStr; // added
int MANumberInt; // added
public: // User declarations
Then I modify the source code I just added to set them up.
Code:
__fastcall TMyNewForm::TMyNewForm(int ANumberInt, AnsiString AStringStr, TComponent* Owner)
: TForm(Owner)
{
MANumberInt = ANumberInt;
MAStringStr = AStringStr;
}
//---------------------------------------------------------------------------
Finally, in the calling form you need to call the new form with the integer and string. Something like:
Code:
int DiffInt = 0;
AnsiString DiffStr = "New Diff";
// Create and destroy new form
try
{
MyNewForm = new TMyNewFor(DiffInt, DiffStr, this);
MyNewForm->ShowModal();
}
__finally
{
delete MyNewForm;
MyNewForm = 0;
}
All this assumes you are creating modal forms.
You can also send data back to the calling form by using pointers and assigning the pointer on the new form's closing method.
Clear as mud?
James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!