title: ActiveX controls with old Delphi versions
body: <p>I'm testing a non visual ActiveX control based on a registered .ocx
  which I import into Delphi using the provided wizard.</p>
  
  <p>Then, I simply put the generated component on the main form of a new VCL application.</p>
  
  <p>Under old Delphi versions (D5 and D2007), when i launch the application, this raise an AV
  during the component initialization.</p>
  
  <p>with Delphi 2009 : no problem, the application starts smoothly.</p>
  
  <p>My questions are : </p>
  
  <p>Are there known enhancements of ActiveX management in recent Delphi versions which 
  can explain  this difference ?</p>
  
  <p>Can I suspect a bug in the ActiveX control, or can I consider the origin of the 
  problem is from old Delphi versions ?</p>
  
  <p>I need to use this component (if tests OK) in D2007.
  Do you think that it is possible to correct the AV problem under D2007 by modifying the D2007 generated .tlb file (for example by trying to use the D2009 generated one)</p>
  
  <p>PS: the ActiveX control is not named, because my question is a general question about Delphi and ActiveX, not about a specific ActiveX control.</p>
  
  <p><strong>Edit :</strong> <br>
  With D2007, the error (an Access Violation) appears during Application.CreateForm(TForm1, Form1);<br>
  and more specifically when the Olecontrol is created : <br></p>
  
  <pre><code>procedure TOleControl.CreateInstance;
  var
    ClassFactory2: IClassFactory2;
    LicKeyStr: WideString;
  
    procedure LicenseCheck(Status: HResult; const Ident: string);
    begin
      if Status = CLASS_E_NOTLICENSED then
        raise EOleError.CreateFmt(Ident, [ClassName]);
      OleCheck(Status);
    end;
  
  begin
    if not (csDesigning in ComponentState) and
      (FControlData^.LicenseKey &lt;&gt; nil) then
    begin
      // ON THE LINE BELOW : the call of CoGetClassObject raise an AV
      OleCheck(CoGetClassObject(FControlData^.ClassID, CLSCTX_INPROC_SERVER or
        CLSCTX_LOCAL_SERVER, nil, IClassFactory2, ClassFactory2));
      LicKeyStr := PWideChar(FControlData^.LicenseKey);
      LicenseCheck(ClassFactory2.CreateInstanceLic(nil, nil, IOleObject,
        LicKeyStr, FOleObject), SInvalidLicense);
    end else
      LicenseCheck(CoCreateInstance(FControlData^.ClassID, nil,
        CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IOleObject,
        FOleObject), SNotLicensed);
  end;
  </code></pre>