[Lazarus] ActiveX, TOLEControl

LacaK lacak at zoznam.sk
Thu Oct 20 10:37:03 CEST 2016


>
>>>
>>>>
>>>> I need help with OCX component (not visual I guess), which I need 
>>>> use in Lazarus application (to control another application, which 
>>>> supplies this OCX control).
>>>> I have imported type library using importtl.exe (new unit was 
>>>> created successfully)
>>>>
>>>> Then in program I have created instance:
>>>>   v := CreateOleObject('SCAPS.ScSamlightClientCtrl');
>>>> or
>>>>   intf := CreateComObject(CLASS_ScSamlightClientCtrl) as 
>>>> _DSamlight_client_ctrl_ocx;
>>> What is the type of your V or intf  variable?
>>
>> V: OLEVariant;
>> intf: _DSamlight_client_ctrl_ocx;
>>
>>> I am wild guessing maybe they are not proper referenced type so the 
>>> object is created and then immediately freed.
>>
>> There is something strange behind scene. I have tried various methods:
> I remember in Delphi, I sometimes have to call CoInitialize and 
> CoUninitialize.
> Not sure if FPC has to do the same.
> Have you tried that?
>
I did debuging in Delphi looking at what is called and I have found, 
that when I add two other lines it works!:
var
   Unknown: IUnknown;
   PersistStreamInit: IPersistStreamInit;
begin
   Unknown := CreateComObject(CLASS_ScSamlightClientCtrl);
   // these two lines are necessary:
   OleCheck(Unknown.QueryInterface(IPersistStreamInit, PersistStreamInit));
   OleCheck(PersistStreamInit.InitNew);
   FSamlightClientCtrl := Unknown as ScSamlightClientCtrl;
  ...
end;

I have no idea why they are needed, but may be that they perform some 
initialization of component ... I also wonder if other users can suffer 
from it ?

-Laco.



More information about the Lazarus mailing list