怎样在form1中调用form2的对象

xy1969 2003-10-15 07:52:20
form1是主窗体
form2中有1个单选钮对象"radiogroup1"

我在form1的一个自定义函数中写下
"if form2.radiogroup1.checked=True then showmessage('ok');"可以编译通过.
但运行到此处时提示出错.不知错在那里?
...全文
43 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xy1969 2003-10-16
  • 打赏
  • 举报
回复
我已在form1中用以下命令调用:

with TForm2.Create(self) do
try
ShowModal;
finally;
free;
end;
end;

并且已在form1的implementation 后面加上uses Unit2;


jackycyl 2003-10-16
  • 打赏
  • 举报
回复
for example, you want to use the button1 that is included in form2,you can do as follows:
at first, you must use 'unit2.pas' in unit1.pas ,then you can add the code:
procedure.......
begin
form2.button1....
end;

that is so easy!
tigerhohoo 2003-10-16
  • 打赏
  • 举报
回复
同意楼上的,应该是Form2已经释放掉了。
hiflower 2003-10-16
  • 打赏
  • 举报
回复
如果照你上面的写法,Form2 关闭后,就被 Free 了,你又怎么取得它上面的东西呢?
with TForm2.Create(self) do
try
ShowModal;
if radiogroup1.checked=True then showmessage('ok');
finally;
free;
end;
end;
cupidvenus 2003-10-15
  • 打赏
  • 举报
回复
form2创建没有?
hmily1688 2003-10-15
  • 打赏
  • 举报
回复
跟你的form2窗体类型有关,如果是fsNormal肯定不能运行,通过如果fsMdichild能运行
afeizai 2003-10-15
  • 打赏
  • 举报
回复
感覺不是添加到uses那麼簡單
pankun 2003-10-15
  • 打赏
  • 举报
回复
同意楼上.
hiflower 2003-10-15
  • 打赏
  • 举报
回复
如果编译通过,可能是 form2 没有创建实例
  • 打赏
  • 举报
回复
同上
47522341 2003-10-15
  • 打赏
  • 举报
回复
form2没获得焦点;不能对它的控件属性进行操作吧;
WGYKING 2003-10-15
  • 打赏
  • 举报
回复
......
KL2 2003-10-15
  • 打赏
  • 举报
回复
方法一:
菜单 file->use unit...
然后选择 unit2(unit2 是form2的文件,unit1 为form1)

方法二:
在代码编辑框
implementation 后面加上
uses Unit2;
Dlwxn 2003-10-15
  • 打赏
  • 举报
回复
uses unit2

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧