form1是mdi子窗体,有button1和edit1,手动创建;form2是普通窗体,有button2和Edit2,程序运行进自动创建,但不显示;
在form1.button1Click事件中有以下语句:
form2.eidt2.text:=edit1.text;
form2.show;在form2.button2Click事件中有以下语句:
form1.edit1.text:=edit2.text //出错,怎样解决?Form1并没有关闭!
//如果将Form1改为自动创建,就没有问题.
在form1.button1Click事件中有以下语句:
form2.eidt2.text:=edit1.text;
form2.show;在form2.button2Click事件中有以下语句:
form1.edit1.text:=edit2.text //出错,怎样解决?Form1并没有关闭!
//如果将Form1改为自动创建,就没有问题.
在form2.button2Click事件中有以下语句:
form1 := Tform1.Create(nil);
form1.edit1.text:=edit2.text
Access violation at address 0055c5f50 in module jhBuyer.exe'. Read of address 0000061c-----------------
以下这个段函数代码创建窗口
formclass是窗体类名,openmode是0或1,0代show,1代表showmodal
with formclass.Create(application) do
begin
try
if openmode=0 then
show
else
showmodal;
except
free;
end;
end;
-----
上面一句话不清楚,到底是什么手动创建
最好贴代码
这样创建了一个隐藏的实例,而Form1并没有创建,这样写就可以了
Form1 := formclass.Create(application);
with Form1 do
begin
try
if openmode=0 then
show
else
showmodal;
except
free;
end;
end;
>>以下这个段函数代码创建窗口
>>formclass是窗体类名,openmode是0或1,0代show,1代表showmodal
>>...
这些代码写在什么地方的?MainForm中?Form2中?
主MainForm中,有菜单项Test,响应函数:
procedure TMainForm.Test1Click(Sender: TObject);
begin
Form2 := TForm2.Create(application);
with Form2 do
begin
try
show; { 为方便,我只用了SHOW方法 }
except
free;
end;
end;
end;主窗体代码中引用了 Unit1 单元(位于implementation后)在Form1中,引用unit2;在Form2中,引用unit1。(均位于implementation后)
Form1中:
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.edit2.text:=edit1.text;
form2.show;
end;Form2中:
procedure TForm2.Button1Click(Sender: TObject);
begin
form1.edit1.text:=edit2.text;
end;工程源代码中:
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TForm2, Form2);
Application.Run;MainForm为fsMDIForm, Form1: fsMDIChild, Form2: fsNormal
function FormCreate(aFormClass:TFormClass;OpenMode :Integer):TForm;
begin
Result := aformclass.Create(application);
with Result do
begin
try
if openmode=0 then
show
else
showmodal;
except
free;
end;
end;
end;
创建Form1时
Form1 := FormCreate(TForm1,0);