Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-10

ActiveX, TOLEControl

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

LacaK

Hi *,

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;

But all next attampts using any interface method fail with EOleSysError "Catastrophic failure" (ErrorCode=-2147418113)

In Delphi it works, but only when I use TOLEControl descendant created by Delphi's import of ActiveX (into _TLB unit)
In Delphi I have :

TScSamlightClientCtrl = class(TOleControl)
...

but in Lazarus I have no equivalent? (When I Delphi I do same as in Lazarus I get same error also in Delphi)

I do not know exacly what to ask here ?
What is purpose of TOleControl and what TOleControl did more than I can do in Lazarus ?
Can I somehow workaround it in Lazarus ?

In short what I have imported from type lib in Lazarus is interface: _DSamlight_client_ctrl_ocx = dispinterface
['{05D31AA6-1306-4DA0-9AE2-A8771FF6FA94}']

    function ScIsRunning:Integer;dispid 1;
   ... etc.

end;

and CoClass:
   Class Function CoScSamlightClientCtrl.Create: _DSamlight_client_ctrl_ocx;
   begin
     Result := CreateComObject(CLASS_ScSamlightClientCtrl) as
_DSamlight_client_ctrl_ocx;
   end;

I can create instance calling CoScSamlightClientCtrl.Create, but as I wrote I can not use any method ...

Can somebody give any help ?

Thanks

-Laco.

Reply by email

Dennis
to LacaK
LacaK wrote 13 lines
Hi *, 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?
I am wild guessing maybe they are not proper referenced type so the object is created and then immediately freed.

I would try
   v : OLEVariant;
or V :  _DSamlight_client_ctrl_ocx;

Dennis

Reply by email

LacaK
to Dennis
Show quoted text 16 lines
> Hi *, > > 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:

var
   v1: OLEVariant;
   v2: ScSamlightClientCtrl;
   v: variant;
   ax: TActiveXContainer;
   disp: IDispatch;
   i: integer;
begin
   v1 := CreateOLEObject('SCAPS.ScSamlightClientCtrl');
   i := v1.scIsRunning;  // exception here
   v2 := CoScSamlightClientCtrl.Create;
   i := v2.scIsRunning;  // exception here
   ax := TActiveXContainer.Create(Self);
   //ax.OleClassName := 'SCAPS.ScSamlightClientCtrl';
   CoCreateInstance(CLASS_ScSamlightClientCtrl, nil,
CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, disp);
   ax.ComServer:=disp;
   ax.Active := True;
   v := disp;
   i := v.scIsRunning;  // exception here

So in every case it returns exception when I try call first time interface method ...
I am not familiar with ActiveX technology so I have no idea what is wrong ?

-Laco.

Reply by email

Dennis
to LacaK
LacaK wrote 25 lines
> > >> Hi *, >> >> 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?

Dennis

Reply by email

LacaK
to Dennis
Show quoted text 28 lines
>> >>> >>> 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.

Reply by email

Jesus Reyes A.
to Dennis: I remember in Delphi, I sometimes have to call CoInitialize and CoUninitialize. Not sure…

En Wed, 19 Oct 2016 11:07:35 -0500, Dennis via Lazarus

Show quoted text 34 lines
LacaK via Lazarus wrote: > >> >> >>> Hi *, >>> >>> 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? Dennis
Usando el cliente de correo de Opera: http://www.opera.com/mail/

Reply by email