Recent

Author Topic: LazActiveX question  (Read 4486 times)

cpalx

  • Hero Member
  • *****
  • Posts: 753
LazActiveX question
« on: May 01, 2012, 12:30:50 am »
I tested ActiveX succesfully with the wiki example http://wiki.lazarus.freepascal.org/LazActiveX

my question is :
How could  i know the classname of an ActiveX???

cpalx

  • Hero Member
  • *****
  • Posts: 753
Re: LazActiveX question
« Reply #1 on: May 01, 2012, 12:47:21 am »
LazActiveX use the ProgID, i use ActiveXhelper to extract the Activex information.

What about the activeX doesnt have a ProgID?

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: LazActiveX question
« Reply #2 on: May 01, 2012, 09:44:13 am »
If you don't have the ProgID then you'll have to activate the ActiveX control at run time using the clsid. For the late binding example using the progid VideoLAN.VLCPlugin.2 this becomes then for example:
Code: [Select]
uses ..., activex;
...
procedure TForm1.FormCreate(Sender: TObject);
var
  disp:IDispatch;
begin
  CoCreateInstance(StringToGUID('{9BE31822-FDAD-461B-AD51-BE1D1C159921}'),nil,CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER,IDispatch,disp);
  ActiveXContainer1.ComServer:=disp;
  ActiveXContainer1.Active:=true;
end;

cpalx

  • Hero Member
  • *****
  • Posts: 753
Re: LazActiveX question
« Reply #3 on: May 03, 2012, 03:08:44 pm »
ok, thanks.

CM630

  • Hero Member
  • *****
  • Posts: 1316
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazActiveX question
« Reply #4 on: March 13, 2025, 09:39:16 am »
I tried to use an ActiveX control in Lazarus, using the same wiki page.
It says:
Quote
There are 3 different ways of using ActiveX components:

1. drop the TActiveXContainer on a form and assign the ActiveX ClassName to the OleClassName property. Suitable for late binding and without direct event support.
2. import the ActiveX type library, drop the TActiveXContainer on a form, instantiate the ActiveX object and assign it to the ComServer property. Suitable for early binding and with event support.
3. create a new component from the type library or the object and drop that new component on the form. This also uses early binding and has full event support. Event handlers can be assigned from the IDE.
When I try the fist method (drag an OCX or a DLL) on the frame I get the following dialogue:

Quote
File "..." does not look like a txt file.
Open it anyway?

Then I tried the second method:
Main menu — Tools — Import Type Library...
I selected an ActiveX control, it got open in text editor mode in the IDE.
Then I dragged the DLL/OCX (the same file, that was shown in the Import Type Library... dialogue).
And I got
Quote
File "..." does not look like a txt file.
Open it anyway?
again.
Am I doing something wrong, shall I tried the third method, because the first two do not work?

Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: LazActiveX question
« Reply #5 on: March 13, 2025, 10:13:35 am »
Am I doing something wrong, shall I tried the third method, because the first two do not work?
Yes, not reading the Wiki properly.
@1) It never says, to Drag/Drop the ocx/dll on the Form.
Drop the ActiveXContainer (!!!) on the Form, and assign the correct CoClassName.
ocx/dll MUST be registered on the machine
@2) It says to import the TYPE-LIBRARY.
To "directly" load an ocx/dll, this file needs a TypeLib-Ressource inside.
If for whatever reason, there is no TypeLib-Ressource you'd need a TLB-File of the ocx/dll
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

CM630

  • Hero Member
  • *****
  • Posts: 1316
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazActiveX question
« Reply #6 on: March 13, 2025, 12:08:45 pm »
Thanks, indeed it is written perfectly well, yet I needed to read it several times to get rid of my confusion.
No I have Windows Media Player playing.

Code: Pascal  [Select][+][-]
  1. ...
  2. OleClassName := 'WMPlayer.OCX.7'; //I found this string in google
  3. ...
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   actx: variant;
  7. begin
  8.   actx := ActiveXContainer1.ComServer;
  9.   actx.URL := 'C:\video.mp4';
  10. end;    
  11.  

But does
Code: Pascal  [Select][+][-]
  1. ...Good documentation for the ActiveX object is very important (sample code for VB can easily be translated to Pascal)...
mean that I have to create a project in VB or other IDE to get the necessary data (OleClassName, Properties and Methods), because Lazarus cannot retrieve and display them?
The properties are available in the .pas file, generated by Main menu — Tools — Import Type Library... in a very convenient name, but the OleClassName is not there.
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: LazActiveX question
« Reply #7 on: March 13, 2025, 01:16:56 pm »
Thanks, indeed it is written perfectly well, yet I needed to read it several times to get rid of my confusion.
No I have Windows Media Player playing.

Code: Pascal  [Select][+][-]
  1. ...
  2. OleClassName := 'WMPlayer.OCX.7'; //I found this string in google
  3. ...
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   actx: variant;
  7. begin
  8.   actx := ActiveXContainer1.ComServer;
  9.   actx.URL := 'C:\video.mp4';
  10. end;    
  11.  

But does
Code: Pascal  [Select][+][-]
  1. ...Good documentation for the ActiveX object is very important (sample code for VB can easily be translated to Pascal)...
mean that I have to create a project in VB or other IDE to get the necessary data (OleClassName, Properties and Methods), because Lazarus cannot retrieve and display them?
The properties are available in the .pas file, generated by Main menu — Tools — Import Type Library... in a very convenient name, but the OleClassName is not there.
That's because you use "Late Binding", so you have no Intellisense-Support for Methods, Properties and Events
"VB Code can be easily translated" --> it doesn't mean you have to install the VB-IDE, it means you just read the VB-Code

Next: OleClassName := 'WMPlayer.OCX.7'; //I found this string in google
It has nothing to do with Google, but everything with what's in your Registry. See screenshot

If you used the second approach (Importing TypeLib)
Quote
import the ActiveX type library, drop the TActiveXContainer on a form, instantiate the ActiveX object and assign it to the ComServer property. Suitable for early binding and with event support.
you should see everything in Code (not the IDE)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

CM630

  • Hero Member
  • *****
  • Posts: 1316
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazActiveX question
« Reply #8 on: March 13, 2025, 03:04:41 pm »
...
If you used the second approach (Importing TypeLib)
Quote
import the ActiveX type library, drop the TActiveXContainer on a form, instantiate the ActiveX object and assign it to the ComServer property. Suitable for early binding and with event support.
you should see everything in Code (not the IDE)
I did not understand
Quote
...instantiate the ActiveX object and assign it to the ComServer property...
but the “Internet Explorer in a form with event support.” example worked (I added some info to wiki).
Still I did not understand how the conclusion that Browser:TEvsWebBrowser; shall be used was reached.
I tried to run Windows Media Player.
I succeeded the following way.

Code: Pascal  [Select][+][-]
  1. var
  2. ...
  3.   MP: TEvsWindowsMediaPlayer;  
  4. ...
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. begin
  8.   mp:=TEvsWindowsMediaPlayer.Create(Self);
  9.   ActiveXContainer2.ComServer:=MP.ComServer;
  10.   ActiveXContainer2.Active:=True;
  11. end;      
  12.  
  13. procedure TForm1.Button1Click(Sender: TObject);
  14. var
  15.   url,onull:Olevariant;
  16. begin
  17.   mp.ComServer.URL := Utf8decode('C:\xxxxxx.mkv');
  18. end;

But the way to MP: TEvsWindowsMediaPlayer was not direct. I just started trying all classes in the autogenerated WMPLib_1_0_TLB. %)
« Last Edit: March 13, 2025, 03:14:32 pm by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018