Recent

Author Topic: How do I import OCX / ActiveX Control  (Read 51947 times)

qoxop

  • New Member
  • *
  • Posts: 33
Re: How do I import OCX / ActiveX Control
« Reply #15 on: October 14, 2011, 03:33:13 pm »
I also search hours for some solution...

and finally I found it here: author Ludo Brands
http://comments.gmane.org/gmane.comp.ide.lazarus.general/52310

or also:
http://lists.lazarus.freepascal.org/pipermail/lazarus/2011-May/063491.html

hope it helps

Code: [Select]
type
  PIUnknown=^IUnknown;
  TAtlAxAttachControl = function(Control:IUnknown; hwind:hwnd;ppUnkContainer:PIUnknown): HRESULT; stdcall;
  IEventIntfEvents = dispinterface
    ['{EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B}']
  end;

procedure TForm1.FormCreate(Sender: TObject);
var
  atl:hmodule;
  AtlAxAttachControl:TAtlAxAttachControl;
  WebBrower:variant;
begin
  atl:=LoadLibrary('atl.dll');
  AtlAxAttachControl:=TAtlAxAttachControl(GetProcAddress(atl, 'AtlAxAttachControl'));
  WebBrower:=CreateOleObject('Shell.Explorer');
  AtlAxAttachControl(WebBrower,panel1.Handle,nil);
  WebBrower.GoHome;
end;

cheers
« Last Edit: October 14, 2011, 03:35:02 pm by qoxop »

Wodzu

  • Full Member
  • ***
  • Posts: 171
Re: How do I import OCX / ActiveX Control
« Reply #16 on: October 14, 2011, 04:35:16 pm »
Wow. Finally!

zzsczz

  • Newbie
  • Posts: 4
Re: How do I import OCX / ActiveX Control
« Reply #17 on: December 20, 2011, 07:02:06 am »
http://www.nohl.eu/tech-resources/using-typelibs-with-freepascal/

idl2pas works well on  freepascal 2.5 or above

1 use sdk's oleview to view typelib (in ocx,dll or tlb) ,  copy and  save the idl to  textfile

2 use idl2pas to generate pas files

3  add pas file to lazarus project....


the attachments file is a lazarus project which use tracetool 12.4's avtivex lib

I use
http://svn.freepascal.org/svn/fpc/branches/fixes_2_6
Revision: 19871

and
lazarus
http://svn.freepascal.org/svn/lazarus/branches/fixes_0_9_30
Revision: 34261

http://www.codeproject.com/KB/trace/tracetool.aspx
http://sourceforge.net/projects/tracetool/


freepascal  can not compile the  delphi version of tracetool sometimes ago
,then  use the activex lib
« Last Edit: December 20, 2011, 07:19:45 am by zzsczz »
fpc : fixes_2_6      r19871
lazarus : fixes_0_9_30 r34261

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: How do I import OCX / ActiveX Control
« Reply #18 on: January 05, 2012, 09:09:33 pm »
Code: [Select]
type
  PIUnknown=^IUnknown;
  TAtlAxAttachControl = function(Control:IUnknown; hwind:hwnd;ppUnkContainer:PIUnknown): HRESULT; stdcall;
  IEventIntfEvents = dispinterface
    ['{EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B}']
  end;

procedure TForm1.FormCreate(Sender: TObject);
var
  atl:hmodule;
  AtlAxAttachControl:TAtlAxAttachControl;
  WebBrower:variant;
begin
  atl:=LoadLibrary('atl.dll');
  AtlAxAttachControl:=TAtlAxAttachControl(GetProcAddress(atl, 'AtlAxAttachControl'));
  WebBrower:=CreateOleObject('Shell.Explorer');
  AtlAxAttachControl(WebBrower,panel1.Handle,nil);
  WebBrower.GoHome;
end;
This is looking great, because it potentially allows me to modify at least 3 of my Delphi (Windows web) applications to work in Lazarus.

So I tried this exact code with Delphi2006 and it worked in my tests & computers. So I decided to test it further and added the code. But now I have received feedback. Previously working application fails to start in Windows7 64-bit after adding the code. (This is strange, because I have this system too and it works fine)

Error message:

"The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher."

I gave another version & another download link, but same problem. I replaced atl code with TOlecontainer. That solved the problem for the user.

Any idea what could be the problem? User just happens to have broken system?

Rocky

  • New member
  • *
  • Posts: 8
Re: How do I import OCX / ActiveX Control
« Reply #19 on: May 01, 2012, 04:30:40 pm »
Quote
"The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher."

Hi! This message seems to be related to 64 bits OS but it's strange in your case. I think ActiveX is not completely tested in Lazarus, event if we can do some interesting things.

For me, I'm trying to use this code but the problem is that the control flickers a lot when I resize.

Code: [Select]
I tried DoubleBuffered := true;
Without success.

I tried to call SetWindowLong with a WS_CLIPCHILDREN style, as seen in another other forum when ATL is used, but it has no effect.

Code: [Select]
SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) or WS_CLIPCHILDREN or WS_CLIPSIBLINGS);
Is there any other possibility? Thanks if someone has a trick.



ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: How do I import OCX / ActiveX Control
« Reply #20 on: May 01, 2012, 04:38:27 pm »
In the latest fpc/lazarus from svn you'll find the new lazactivex package which doesn't rely on external atl libraries anymore and is fully integrated in lazarus. http://wiki.freepascal.org/LazActiveX

Rocky

  • New member
  • *
  • Posts: 8
Re: How do I import OCX / ActiveX Control
« Reply #21 on: May 01, 2012, 05:29:00 pm »
Thanks for reply.

I tried to install the latest daily build (Lazarus 1.1), when I check LazActiveX in packages, and try to rebuild it, I get an error about a unit (don't remember). Perhaps this is because I installed the version over an existing installation of Lazarus? I'm not on the test computer today, but will try again tomorrow. If it's integrated, it's great but using the ATL method is also interesting.

But the good news is that Lazarus is moving towards a true alternative to Delphi, even in Windows platform.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: How do I import OCX / ActiveX Control
« Reply #22 on: May 01, 2012, 05:38:29 pm »
You need also fpc from svn. 2.6.1 fixes is fine but 2.7.1 has some fixes not back ported to 2.6.1 yet, I believe.

Rocky

  • New member
  • *
  • Posts: 8
Re: How do I import OCX / ActiveX Control
« Reply #23 on: May 01, 2012, 05:46:00 pm »
There is no build with FPC 2.7.1 on this page : http://freepascal.dfmk.hu/test/lazarus/

Instead of breaking everything, I prefer to wait a little more until the next version is finished.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: How do I import OCX / ActiveX Control
« Reply #24 on: May 01, 2012, 06:04:36 pm »
You can use the one with 2.6.1. I just checked and the relevant 2.7.1 fixes where merged in a week ago.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: How do I import OCX / ActiveX Control
« Reply #25 on: May 02, 2012, 12:00:52 pm »
This is great.

Does anyone know how to use events (like DocumentComplete) with this kind of IE control ?

Is there any way to read HTML content of an loaded web page (to put it in simple Memo) ?

Thx
« Last Edit: May 02, 2012, 12:38:15 pm by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: How do I import OCX / ActiveX Control
« Reply #26 on: May 02, 2012, 01:51:37 pm »
Is there any way to read HTML content of an loaded web page (to put it in simple Memo) ?
I don't think so. Document sources are parsed in objects (DOM) and you can access these but afaik not the original sources. The source of a page is in many cases several html documents and sometimes a lot of html added and/or modified by scripts.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: How do I import OCX / ActiveX Control
« Reply #27 on: May 02, 2012, 02:29:49 pm »
Quote
The source of a page is in many cases several html documents and sometimes a lot of html added and/or modified by scripts.

Yes and this is OK.

Quote
Document sources are parsed in objects (DOM) and you can access these ...

How ?

In Delphi I used :

var  Doc: IHTMLDocument2;
       WebForm: IHTMLFormElement;
       FormElements: OleVariant;

.....

      Doc := WebBrowser.Document as IHTMLDocument2;
      WebForm := Doc.Forms.Item(0,'') as IHTMLFormElement;
      FormElements := WebForm.Elements;

    Memo1.Lines.Text := WebBrowser.OleObject.Document.documentElement.innerText;

 How can it be made in Lazarus ?



« Last Edit: May 02, 2012, 03:32:14 pm by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: How do I import OCX / ActiveX Control
« Reply #28 on: May 02, 2012, 04:05:13 pm »
Quote
In Delphi I used :

...

 How can it be made in Lazarus ?
The same  ;) But in order to do this you should also add the full mshtml typelib. Import the typelib from C:\WINDOWS\system32\mshtml.tlb and add the created MSHTML_4_0_TLB (75000 lines!)  to your uses clause.

I extended the code used on the wiki a bit and added a tmemo and a second tbutton:
Code: [Select]
uses ..., MSHTML_4_0_TLB;
...
procedure TForm1.Button2Click(Sender: TObject);
var  Doc: IHTMLDocument2;
begin
  Doc := Browser.ComServer.Document as IHTMLDocument2;
  Memo1.Lines.Text := utf8encode(Doc.parentWindow.document.Get_body.innerHTML);
end;
This shows the contents of the <body> tag.

Rocky

  • New member
  • *
  • Posts: 8
Re: How do I import OCX / ActiveX Control
« Reply #29 on: May 02, 2012, 07:35:24 pm »
Today I tested the daily build installing in another directory. When I started it, I correctly configured the paths.

The LazActiveX module was checked and the Lazarus IDE compiled without problems, but any applications that I started with it trowed a SIGILL on start. I don't know the exact cause.

For my flickering problem, I searched a bit in the constants, this is the solution :

Code: [Select]
 
SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) or WS_CLIPCHILDREN or WS_CLIPSIBLINGS);
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_COMPOSITED);

Adding this in the FormCreate event will make the window resize smoothly.

Maybe this could be interesting to solve other flickering problems.