Delphi uses VB control Raiders
Foreword
In recent weeks, it is always troubled by a headache, that is, the ActiveX controlled ActiveX control written by VB6 has many strange weird problems in the Delphi environment. After several turnover, I finally searched almost all forums, after the information I found a solution for problems that occur against 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 met this question, I was almost angry because I didn't explain anyone in 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 way to be almost Magic (the discoverer is called this:
A method of manually modifying Delphi imports After the VB ActiveX control, the method of the agent type library XXX_TLB.PAS (here XXX refers to the control class name) file can solve this problem. for example:
There is a VB written control userControl1, generates two files after importing in Delphi, one of the userControl1_tlb.pas is the file we want to modify.
Find similar in the file
FINTF: _USERCONTROL1;
Function getControlInterface: _UserControl1;
with
Property ControlInterface: _UserControl1 Read getControlInterface;
GetControlInterface;
as well as
Procedure tuserControl1.createcontrol;
PROCEDURE DOCREATE;
Beginfinf: = IUNKNOWN (oleobject) as _userControl1;
END;
Begin
IF FINF = NIL THEN DOCREATE;
END;
Function TuserControl1.getControl1Interface: _UserControl1;
Begin
CreateControl;
Result: = FINFL;
END;
Please note: The red-labeled _UserControl1 is all replaced with _ userControl1disp, if the compilation is unsuccessful, please change the _UserControl1 in the compilation warning to _UserControl1disp, compiled, this is called when the control method is called The above fatal mistakes will not appear.
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 inexplicable fatal abnormalities
However, Delphi did not let me get around this restriction, very quickly, the customer discovers another trouble, in the development environment, the form that turns off the control at a time run each time an exception Error, but not in the compiled application, although it does not affect the use of end users, this is a small trouble for developers, and then I use the above example to try, I don't happen. this problem. (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 (which you can contain other controls), you will not add a WindowSS control such as Label, Line, Image (that is, no Window controls, they are running at the VB real-time), otherwise you will get the above error report.
Delphi 6,7 hidden ActiveX control
It is because there is a terrorist experience below delphi5, I found it still necessary to test the same problem in Delphi6 and 7 (previous version because the user is very unpleasant, Delphi8 has not officially official, also temporarily Not considered.). The result is: ... no matter how many times I load, I have never found the small icon in the ActiveX column. This result is of course funny, I can't even make it even, don't talk about what test is not normal.
Similarly, I searched for all kinds of forums and websites. I also found more similar problems in 9cbs, but the answer or zero, helpless, I have to adjust the options in each Delphi6, 7 ...
After 3 hours and 15 minutes and 54 seconds, I found this damn problem (please forgive me for this call, I really can't bear it), or a solution, it is actually very simple. Now, please do it: Click the Tools Menu -> Environment Options-> Type Library page, we should find one: Ignore Special Coclass Flags When Importing, select it, then select CAN CREATE one, then now we try again Go to import that poor ActiveX control (here you should pay attention, if you have imported once, please delete the two files .dcr and .pas files, otherwise it will not be refreshed). If you still can't find that control in the ActiveX column, then you only call Microsoft or Borland, ask when they can make a family, huh, huh!
(Immediately, the above errors occurred in Delphi5 are not found in Delphi6 and 7)
My test environment is:
Win2k
Delphi 5 Update1
Delphi 6 Update22
Delphi 7