MDI 工程创建第二个子窗体时出错

Oceanable 2023-02-02 22:23:43

MainForm 是 MDI 主窗体;Manager 与 GraphicWindow 都是 Child 子窗体。

加入括号 { } 内的这段代码,就报错,很奇怪,,,

没有这段代码的话,一切正常,,,

procedure TMainForm.FormResize(Sender: TObject);
begin

  if Manager = Nil then Manager:= TManager.Create(Self);
  Manager.Show;

  { if GraphicWindow = Nil then GraphicWindow:= TGraphicWindow.Create(Self);

       GraphicWindow.Show; }  只要插入{}这段代码,就报错,,,

  Manager.Width:= MainForm.Width div 5;
  Manager.Height:= MainForm.Height - 120;
  Manager.Left:= 0;
  Manager.Top:= 0;

end;

 

 

...全文
190 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

小coder,看来你还是油梭子发白呀~

  • 打赏
  • 举报
回复
不要@我了
  • 打赏
  • 举报
回复
我怕你了日本狂人 题主我帮不了你了环境卸载好多年了来Java吧
@「已注销」 你呀,理解力真差~
  • 打赏
  • 举报
回复
真无聊这也要杠都去用Java写桌面嘛
@「已注销」 你要知道这里既不是c#版,也不是java版,是你跑来杠的~
Oceanable 02-03
  • 打赏
  • 举报
回复

我们这种不是计算机专业的,跟不上这么快的技术更新速度。
----- delphi VB 就能解决所有问题,,主要是计算,,界面当然也很重要,但是需求不是那么迫切 (^o^)/~

  • 打赏
  • 举报
回复

还在用delphi啊推荐c#做窗体与delphi一脉相承而且vs好用的多号称IDE天花板

@「已注销」 .net is dead, c# is dying~
@「已注销」 c#做窗体就是WinForms、WPF,都是早就淘汰的东西,2014年之后就没更新过,而且只能用在windows上
  • 举报
回复
@日立奔腾浪潮微软松下联想 但是也不会用Java去写桌面应用
6条回复
tanqth 02-03
  • 打赏
  • 举报
回复

TGraphicWindow创建或显示时本来就有错误。
你这个错误,通常是什么类没有创建就想去使用,或者说已经释放了你还想使用。

tanqth 02-03
  • 打赏
  • 举报
回复

你单独执行:
if GraphicWindow = Nil then GraphicWindow:= TGraphicWindow.Create(Self);
GraphicWindow.Show;

会不会报错??

初步估计是你GraphicWindow里有问题,与是不是 Child 子窗体以及是不是两个窗体无关。

Oceanable 02-03
  • 举报
回复
@tanqth 本来两个子窗体都是采用 auto Create 的方式创建的,后来 Manger 出现【非法访问】问题,我才自己 Create。 另外还有一种情况,就是我去掉 11-14 行,保留 { } 的内容,一切也正常。 所以,两个子窗体 各自应该都是没问题的,问题在于 MDI 这种方式,,,,
tanqth 02-03
  • 举报
回复
@Oceanable 可能是GraphicWindow修改了Manger ,所以后面11-14找不到对应的Manger ,就出错了。检查一下GraphicWindow的内容,或者先建一个空的窗体代替GraphicWindow试试。
Oceanable 02-03
  • 举报
回复
@tanqth 【1】刚才新建了个工程,只有三个空的窗体(MDI + 2 Child),一切正常。 【2】回到原来的工程,发现问题竟然出现在 MainForm 上: ------------------------------------------------------------------------------------------------------------------------------------- procedure TMainForm.FormResize(Sender: TObject); begin if MainForm = Nil then exit; // 加上这句,拉伸主窗体一点反应都没有,直接 exit 了,,,,,, Manager.Width:= MainForm.Width div 5; Manager.Height:= MainForm.Height - 120; Manager.Left:= 0; Manager.Top:= 0; GraphicWindow.Width:= MainForm.Width - Manager.Width - 20; GraphicWindow.Height:= MainForm.Height - 120; GraphicWindow.Left:= Manager.Width; GraphicWindow.Top:= 0; Self.HorzScrollBar.Visible:= false; Self.VertScrollBar.Visible:= false; end; -------------------------------------------------------------------------------------------------------------------------------------
4条回复
BlueStorm 02-03
  • 打赏
  • 举报
回复

用Delphi 10.3.3测试了一下, 没有报错

Oceanable 02-03
  • 举报
回复
@BlueStorm 这确实很奇怪,我开始 auto create 的时候,都没问题的,不知道怎的,突然 manager 非法访问了 ..... 记得是 manager 的 unit 另存为,改了下名字,就 XXXXX 了
Oceanable 02-03
  • 举报
回复
@BlueStorm procedure TMainForm.FormResize(Sender: TObject); begin if Manager = Nil then Manager:= TManager.Create(Self); Manager.Show; if GraphicWindow = Nil then GraphicWindow:= TGraphicWindow.Create(Self); GraphicWindow.Show; // ------ 加了上面这两段,关闭 Child 窗体然后【拉伸】主窗体就报错,是来不及创建对象 ??? Manager.Width:= MainForm.Width div 5; Manager.Height:= MainForm.Height - 120; Manager.Left:= 0; Manager.Top:= 0; GraphicWindow.Width:= MainForm.Width - Manager.Width - 20; GraphicWindow.Height:= MainForm.Height - 120; GraphicWindow.Left:= Manager.Width; GraphicWindow.Top:= 0; Self.HorzScrollBar.Visible:= false; Self.VertScrollBar.Visible:= false; end;

5,283

社区成员

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

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