Home > Back-end >  Class release if there is a conflict, a null pointer error?
Class release if there is a conflict, a null pointer error?

Time:09-16

Using Delphi7 development tools, custom main form MainForm class, class B and class C, among them the main form class, class B in part Uses reference class C, B class frequently the creation of a release of C, main form class TClientSocket controls, in the control of the Read event using the two functions, class C program without error at compile time, but now the problem is: this program is running after a period of time, suddenly jump out to a wrong window, prompt "null pointer errors," program will completely stop running;
I want to ask, frequent B class can be created and release of C, will affect main form class used in the C class? "Null pointer errors can cause this?

CodePudding user response:

Is clearly in the other thread operating variables in the main thread, for the old version, you can use the Synchronize method, the new version (I forget which version from the start, but for a long time) can be directly with the components of the BeginInvoke + anonymous methods

CodePudding user response:

Problem is that this program does not use multithreading, is a few custom class, there is only one kind of operating a serial port, other classes are processing TClientSocket controls to send data, receive data,

CodePudding user response:

You are not used, but TClientSocket use...

CodePudding user response:

Class reference, refer to the release of nil values, to solve such problems, must be considered in the design,

CodePudding user response:

Object what you said is "main form" and "B" object using the common object "C", this would be a problem, when the main form to the use of "C" C may not be instantiated or has been released, low-level mistakes!
There are three kinds of correct method of use: 1. Put the two functions in public in the cell, don't in class; 2. Add the class keyword in front of these two functions as a static method using inside (but must ensure that no call other resources); 2. Have some similarities with method 1, will all public functions encapsulated into a static class (in front of all the methods and the class keyword),

CodePudding user response:

Before you use a class with assigned to judge the existence of the class and if there is no can create one
  • Related