The Formshow event of the main form in Delphi invokes an error before the program automatically creates the Form object.

Source: Internet
Author: User

Well, I don't know how to write the title, actually. It's a little difficult to describe a mistake in a sentence.

Let's use the code to illustrate it.

Recently done a Delphi program, according to my habit is usually to create a form as the main form, the other forms are displayed on this basis. In addition, because the database is used, a tdatamodule control is added, which makes it easier for some cells that cannot prevent the control from doing database operations. All other forms are set to non-automatic creation. It is then dynamically created and invoked through the Application.createform method.

Okay, here's the problem.

The following code is in the project file:

Application.createform (Tfrmmain, frmmain);
Application.createform (Tdatam, Datam);
Application.Run;

There are formshow methods in Frmmain, which have some functions for initializing variables and code for loading skins. In particular, there is a function in the initialization variable that uses the

The Datam.qry statement. It is not a problem to call Datam objects in the Formshow method of Frmmain. Because the corresponding object has been created in the code above. However, I am in the debugging of the constant error, the hint is unable to find Datam object. It's so weird.

No way, I had to put the creation Datam statement mentioned before creating frmmain. The program is able to run, but this is unreasonable ah.

Synchronous unremitting efforts, and compared to the previous backup of the program to compare and finally found the error. Originally, the Delphi display main interface is through the Application.Run to show the main form, and I debug the program when accidentally click the mouse when the main form of the Visible property by the correct "false" changed to "true". So, a little program executes Application.createform (Tfrmmain, Frmmain) when it's time to show this window, because true. No Datam was created on show, and show called Datam. Therefore, an error that is called without creating an object occurs.

The Formshow event of the main form in Delphi invokes an error before the program automatically creates the Form object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.