Delphi uses VB written ActiveX control full Raiders
In the last few weeks of work, it has been plagued by a headache. It is the ActiveX control written by VB6 in the delphi environment. There are several twists and turns. It is finally searching for almost all forums, information After that, I found a solution for problems in different Delphi versions. Delphi 5 inexplicable fatal exception first, let's take a look at the strange performance of the ActiveX control written by VB in Delphi 5. For example: We write a control Usertest with VB (for simplicity, we only export a class, user control), a property testname, a method TestMethod. Then compile it into an ActiveX control, register and import Delphi5 development environment (above the steps, please check all kinds of reference materials, there is definitely a standard answer), so far, it seems that everything is normal. Then, we are used to drag and drop the control on the form, adjust the size, assign values for attributes in the property window, or in the code, very normal, easy to use. However, the following question is coming, if you call the TestMethod, you will get a weird exception "Ole Error 800A01A9", then the program exits, and very unfortunately, you will not be able to track this exception. In Delphi or VB, of course, if you are in line with the compilation, you can follow the Delphi debug window step by step ... When I first encountered this problem, I was almost angry. Because whether it is Microsoft or Borland, there is no explanation for this error, and there is no information that can be found. I have to ran to several forums that are often going. Of course, the most important thing is 9CBS, search similar questions in the VB version and Delphi version, and then very unfortunately, only similar problems, and there is no answer, a big customer With this development tool, I have tested the development tools and development environments on Windows (including desktops and web), but almost forgot Delphi. In the rest of the two days, I almost all around the world, call all friends, ask Delphi's master knowing this situation, and finally, I have found a link from Google, but unfortunately, now I forgot now. The specific location of the link, but I got a near MAGIC method (the discoverer is called it): a manual modification of Delphi to import the agent type library generated after the VB ActiveX control is generated by the agent type library XXX_TLB.PAS (here XXX refers to the control The method of the class name) file can solve this problem. For example: There is a VB written control userControl1, generate two files after importing in Delphi, one of which userControl1_tlb.pas is the file we want to modify.
Find in Files similar FintF: _UserControl1; Function GetControlInterface: _UserControl1; and property ControlInterface: _UserControl1 read GetControlInterface; GetControlInterface; and procedure TUserControl1.CreateControl; procedure DoCreate; begin Finf: = IUnknown (OleObject) as _UserControl1; End; Begin If Finf = nil then DoCreate; End; Function TUserControl1.GetControl1Interface: _UserControl1; Begin CreateControl; Result: = Finfl; End; Note: this red marked _UserControl1 to be replaced all _ UserControl1Disp, if the compiler is not successful, then set the compiler warnings The reported _userControl1 is all replaced with _UserControl1Disp, which is compiled so that the above fatal errors will not appear when the method is called. Thanks to this great discovery, I can only describe it so, otherwise I will not have it in this circle, or use another tool to re-develop this control (I am unimaginable to imagine how much work will be, Or it may have other compatibility issues). Delphi 5 inexplicably fatal abnormalities but, Delphi did not let me get around this limit, very fast, the customer discovers another trouble, in the development environment, close the load every time The controls of the control will jump out an exception error, but it will not be used in the compiled application, although it will not affect the use of end users, this is a small trouble for developers, and then I use the above example Try, find that this problem will not happen. (I am crazy, this is likely to be some incompatible usage in the code. When I look for the 10,000 lines of code, it is very symptomous thing to be a very horrible thing) I am, shield my control. All the code, leaving only the user interface itself, then the strange thing happened, I didn't write anything, but I put my control still happened, which made me happily and shocked, and I was this problem. My code has nothing to do so, it will be more convenient to find it; the thrower is just the standard control in several VBs, which will also cause this horror, the contradiction between Delphi5 and VB6 is really a general deep. In the next 2 hours, I constantly delete the control on the interface to test who has caused this fatal anomalies. After 2 hours, I was so angry, the problem found, the fundamental question is: If you use a container control like Frame and PictureBox in the VB user control (you can include other controls inside it), then you will Windowless controls such as Label, Line, Image, which are not available in these controls (that is, window controls, they are running at VB live), otherwise you will get the error report above.