如何对动态创建的窗体的EDIT赋值。(50分)

  • 主题发起人 主题发起人 weibinggui
  • 开始时间 开始时间
W

weibinggui

Unregistered / Unconfirmed
GUEST, unregistred user!
我一共有三个窗体,Main,Form1,Form2,<br>我现在要实现的是,在MAIN上动态创建Form1,FROM1上有一个EDIT1,创建之后,在FROM1点击按钮动态创建Form2,然后在FROM2上点按钮,能对动态创建的FORM1上的EDIT1进行赋值.<br>请问大家是如何处理这种对动态创建的窗体进行赋值的,分不多,请大家帮帮忙.<br>我这样做是错的.<br>Main创建FORM1<br>procedure TMain.Button1Click(Sender: TObject);<br>var<br>&nbsp; NewForm:Tform1;<br>begin<br>&nbsp; newform:=Tform2.Create(Application)<br>&nbsp; newform.Name :='form1';<br>&nbsp; try<br>&nbsp; &nbsp; newform.ShowModal ;<br>&nbsp; finally<br>&nbsp; &nbsp; newform.Free;<br>&nbsp; end;<br>end;<br><br>FORM1 创建FORM2<br>var<br>&nbsp; NewForm:Tform2;<br>begin<br>&nbsp; newform:=Tform2.Create(Application);<br>&nbsp; newform.Name :='form2';<br>&nbsp; try<br>&nbsp; &nbsp; newform.ShowModal ;<br>&nbsp; finally<br>&nbsp; &nbsp; newform.Free;<br>&nbsp; end;<br>end;<br><br>FROM2的点击事件.<br>form1.Edit1.Text :='123';<br>&nbsp; close;<br><br>出错<br><br>---------------------------<br>Debugger Exception Notification<br>---------------------------<br>Project Project2.exe raised exception class EAccessViolation with message 'Access violation at address 0044F026 in module 'Project2.exe'. Read of address 000002FC'. Process stopped. Use Step or Run to continue.<br>---------------------------<br>OK &nbsp; Help &nbsp; <br>---------------------------
 
form1 没有实例化<br>你用 newform
 
newform是局部变量没法在FORM2的代码里用。<br>楼主要用全局变量Form1来记录TForm1的实例才行。
 
procedure TMain.Button1Click(Sender: TObject);<br>var<br>&nbsp; NewForm:Tform;<br>begin<br>&nbsp; newform:=Tform.Create(Application);<br>&nbsp; newform.Name :='form1';<br>&nbsp; try<br>&nbsp; &nbsp; newform.ShowModal ;<br>&nbsp; finally<br>&nbsp; &nbsp; newform.Free;<br>&nbsp; end;<br>end;<br><br>FROM2的点击事件.<br>&nbsp; form1.Edit1.Text :='123';<br>要用这事件~ 在Form2 加 use form1
 
谢谢大家!
 
后退
顶部