Home > Back-end >  Questions about access to dynamically create the form control
Questions about access to dynamically create the form control

Time:10-02

Good god, meet a problem, struggled for several years,
Problem description:
Form 1, name=Form1, form 2, name=Form2, if the form 1, 2 are static, so if in the forms 1 visit form 2 for a button, then I can directly in the function in form 1 write Form2 - & gt; For the="hello".
Now the problem is that if the form of 1 is created dynamically, if be created in the form of 0, create code:
* * pForm TForm;
PForm=new TForm1 (Application);
PForm - & gt; ShowModal ();
Form 2 is a function of a form 1 dynamically created, create code is the same, if I want to be in the form of 2 is closed with some may affect the data in form 1, need to access the controls in form 1, is the problem, I tried several ways are not, I do not know what a great god can help answer, thank you very much,
Programming environment: CB6.

CodePudding user response:

* * pForm TForm;
PForm=new TForm1 (Application);
PForm - & gt; ShowModal ();

Note that pForm is a local variable, you need to create a global variable to hold form1 and form2
This is no problem

CodePudding user response:

reference 1st floor LinuxCard response:
* TForm * pForm;
PForm=new TForm1 (Application);
PForm - & gt; ShowModal ();

Note that pForm is a local variable, you need to create a global variable to hold form1 and form2
This is no problem to pull

I'll try. Thank you

CodePudding user response:

Direct access to the form above resources contain form 1 of CPP files can also, but will die very miserably, access between suggest you like this kind of form by the parameter
 void __fastcall TKeyBao: : ScannerButtonClick (TObject * Sender) 
{
ScannerBarCode (ScanTimeOut * 100);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Bool __fastcall TKeyBao: : ScannerBarCode (int TimeOut)
{
Bool Ret=false;
MsgEdit - & gt; Text="";
The Capture TCaptureForm *=new TCaptureForm (this, the TimeOut);
If (the Capture - & gt; ShowModal ()==mrOk)
{
MsgEdit - & gt; Text=the Capture - & gt; EnCodeStr. The Trim ();
Ret=true;
}
Delete the Capture.
Return Ret.
}
in the form of the constructor to do the corresponding processing
 __fastcall TCaptureForm: : TCaptureForm (TComponent * Owner, unsigned int TimeOut) 
: TForm (the Owner)
{
M_capture=NULL;
EnCodeStr="";
TimeOutCount=(TimeOut * 1000)/CaptureTimer - & gt; The Interval;
}
and so on back to form closed variable can directly use public variables, in the header file in such a statement
 public://User declarations 
String EnCodeStr;
__fastcall TCaptureForm (TComponent * Owner, unsigned int TimeOut);

CodePudding user response:

Dynamic changes to the window that created it is best to create the main window of data,

To be used if not you, in the main window declare a form2 pointer, the main window to call,
TForm2 * pForm2;
Initialization:
Form1 - & gt; In the oncreate pForm2=NULL
Create:
If (pForm2==NULL) pForm2=new TForm2 (... );
Call:
If (pForm2) pForm2 - & gt; For the - & gt; Click ();
Destruction:
If (pForm2) delete pForm2; PForm2=NULL;

Do a pointer can specify a window,
  • Related