tags:

views:

256

answers:

1

I'm testing a non visual ActiveX control based on a registered .ocx which I import into Delphi using the provided wizard.

Then, I simply put the generated component on the main form of a new VCL application.

Under old Delphi versions (D5 and D2007), when i launch the application, this raise an AV during the component initialization.

with Delphi 2009 : no problem, the application starts smoothly.

My questions are :

Are there known enhancements of ActiveX management in recent Delphi versions which can explain this difference ?

Can I suspect a bug in the ActiveX control, or can I consider the origin of the problem is from old Delphi versions ?

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)

PS: the ActiveX control is not named, because my question is a general question about Delphi and ActiveX, not about a specific ActiveX control.

Edit :
With D2007, the error (an Access Violation) appears during Application.CreateForm(TForm1, Form1);
and more specifically when the Olecontrol is created :

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 <> 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;
A: 

As far as I remember there were major enhancements to the ActiveX/TLB import in Delphi 2009 (related to Unicode support) - that might explain it.

In my personal experience Delphi 7 and Delphi 2007 repeatedly failed to import some Windows 7 type libraries (various new interfaces to work with new taskbar), but Delphi 2009 managed that without any problems at all.

As for using Delphi 2009 generated file in earlier versions - beware of Unicode issues. Plus it won't help if the defect is in RTL... Try to make a wrapper ActiveX in Delphi 2009 and use it in Delphi 2007 - that should work.

Alex T.
thank you for feedback on your experience. I tried your idea with the wrapper build with D2009 but got the same AV. I will consider to move my project to D2009... as it seems to be the only way to have a good ActiveX handling.
DamienD
I also accept your answer as it makes clear that my problem comes from bad/incomplete ActiveX/tlb management in previous Delphi versions.
DamienD