I have a main form with TPanel. I have also a Form2 with a TButton which I show in TPanel as a child. I mean TPanel of main form is parent of Form2. I use these steps to create the form2 in MainForm OnCreate method
MainFormOnCreate()
Form2 := TForm2.create(nil)
Form2.Parent := Panel1;
Form2.show;
But the problem is that when I access the button on Form2 it does nothing. For example, when I want to disable the button on Form2 I use this method
A button2 on main form with on click event
btn2OnClick();
Form2.btn.enabled := false;
But it does nothing. Some friends says it's because of child to TPanel it will get no message.
So give me a solution. Thanks in advance
The main problem is, that you create 2 instances of
TForm2.Your
.dprfile look like thisAfter you create an instance of
TForm2inTForm1.OnCreateand save this instance into global variableForm2, another instance ofTForm2is created and stored intoForm2.In the
TForm1.btn5.OnClickevent you address the second created, non visibleTForm2.Solution
TForm2from AutoCreate ListTForm2created inside ofTForm1in a private class field ofTForm1Your code should look like this
.dpr file:
Unit1.pas