简体   繁体   English

在启动时在C ++ Builder中打开两种形式

[英]Open two forms at startup in c++ builder

I want to open two different forms when running my program. 我想在运行程序时打开两种不同的形式。 Forms are named Form2 and Form3. 窗体分别命名为Form2和Form3。 Form2 runs normally, but Form3 doesn't. Form2可以正常运行,但Form3不能正常运行。 I have put Application->CreateForm(__classid(TForm3), &Form3); 我已经把Application->CreateForm(__classid(TForm3), &Form3); on my project cpp file and Form3->Show(); 在我的项目cpp文件和Form3->Show(); in my Unit2.cpp file, but I get error: "Access violation at address 0047B2CE in module 'Project2.exe'. Read of address 00000384." 在我的Unit2.cpp文件中,但是出现错误: "Access violation at address 0047B2CE in module 'Project2.exe'. Read of address 00000384." What am I doing wrong? 我究竟做错了什么?

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() . 没有看到您的实际代码,很难说,但是当您调用Form3->Show()时,很可能尚未创建Form3 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. 您在接近0的内存地址处遇到错误,这很好地表明您可能正在访问NULL指针。

You don't need to call Show() unless you want more control over WHEN the Forms are shown. 您不需要调用Show()除非您希望对显示窗体的时间有更多的控制。 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. 您可以在设计时简单地将其Visible属性设置为true,并在调用Application->Run()启动消息循环时让VCL为您显示它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM