本文介绍了在启动时在C ++ Builder中打开两种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行程序时打开两种不同的形式.窗体分别命名为Form2和Form3.Form2可以正常运行,但Form3不能正常运行.我将 Application-> CreateForm(__ classid(TForm3),& Form3); 放在我的项目cpp文件中,并将 Form3-> Show(); 放在我的Unit2中.cpp文件,但出现错误:模块'Project2.exe'中地址0047B2CE的访问冲突.读取地址00000384." 我在做什么错了?

I want to open two different forms when running my program. Forms are named Form2 and Form3. Form2 runs normally, but Form3 doesn't. I have put Application->CreateForm(__classid(TForm3), &Form3); on my project cpp file and Form3->Show(); in my Unit2.cpp file, but I get error: "Access violation at address 0047B2CE in module 'Project2.exe'. Read of address 00000384."What am I doing wrong?

推荐答案

虽然看不到您的实际代码,但是很难说,但是很可能您尚未创建 Form3 调用 Form3-> Show().您在接近0的内存地址处遇到错误,这很好地表明您可能正在访问NULL指针.

Without seeing your actual code, it is hard to say, but chances are that Form3 has simply not been created yet when you are calling Form3->Show(). You are getting an error at a memory address close to 0, which is a good indication that you are likely accessing a NULL pointer.

除非您希望在显示表单时获得更多控制权,否则无需调用 Show().您只需在设计时将其 Visible 属性设置为true,然后在调用 Application-> Run()启动消息循环时,让VCL为您显示它们即可.

You don't need to call Show() unless you want more control over WHEN the Forms are shown. You could simply set their Visible property to true at design-time and let the VCL show them for you when Application->Run() is called to start the message loop.

这篇关于在启动时在C ++ Builder中打开两种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 04:46