Lazarus

Programming => Operating Systems => Windows => Topic started by: Lazarususer6789 on May 02, 2010, 03:09:01 pm

Title: How do I import OCX / ActiveX Control
Post by: Lazarususer6789 on May 02, 2010, 03:09:01 pm
I want to know what The Lazarus equivalent of vb6 clicking
Project > components >Browse >"using common dialog to get ocx or dll" >ok >click the new icon on the left draw a box with cursor and Its done
i don't care if i have to get some dll's as long as they not ie dlls
i need it to work on all 32 bit windows os  after windows 95 except windows vista and 7 if your method not work in vista like 99.9% of everything


I want to
.insert an ocx Active X into a form
.edit size with code (if the form resizes the activex will also resize)
.i want to make an exe that looks for an ocx in the same folder insted of the clsid in the registry like in vb where it has this code

classid="CLSID:920DFF5F-2EE6-4867-93A5-7BCF15B0F1C2"
id=Activex2
Filename="Activex1.ocx"
In the vb exe if the ocx is not registered or not there it uses ocx in app.path

So basically i want to use activex in Lazarus the same way i use it in vb5/6
Like this i want to make something like this In Lazarus
_______________
|_Form______|X|
|  _________     |
|  | Active X |   |
|  |   Here    |   |
|  |________|   |
|_____________|
Title: activex
Post by: Lazarususer6789 on May 03, 2010, 06:25:39 pm
OK
Title: Re: how do i import ocx
Post by: felipemdc on May 04, 2010, 09:49:03 am
Using OCX controls with Lazarus is not a well established technology and not recommended for a beginner. It still needs to be researched as far as I know and therefore should require considerable work to get working.

On the other hand you have to consider that OCX controls are both obsolete (VB 6 is also obsolete) and Windows only. Also consider that there are lot's of existing components for Lazarus which are cross-platform, so it's better to ask how to achieve the functionality that the OCX control would provide.
Title: Re: how do i import ocx
Post by: felipemdc on May 04, 2010, 07:40:04 pm
I think there is no easy answer for this problem, it is a complex program that you are trying to create. You have to start reading the OCX documentation from Microsoft and search for what is necessary to achieve this.
Title: Re: how do i import ocx
Post by: Wodzu on May 05, 2010, 06:32:24 am
On the other hand you have to consider that OCX controls are both obsolete (VB 6 is also obsolete) and Windows only. Also consider that there are lot's of existing components for Lazarus which are cross-platform, so it's better to ask how to achieve the functionality that the OCX control would provide.

If they are obsolete then what is the replacement for them?
Actually, the argument that something is Windows only is a bit annoying.  ;D After all there are a lot of things that are platform specific and they are handled by the Lazarus.

Personally I think that ActiveX is a nice technology and in the spirit of RAD. Just an example from the real life:

Few weeks ago I've received a scales (I do not know if it's a correct english word - by "scales" I mean device to measure weight) which I need to program. Each measurment needed to be store in database. Without an ActiveX control which provides me GUI and events out of the box I would have to write own wrapper for the dll, own GUI and I would need to test it. How long would it take? For me few hours probably. How long it took me with already premade control? Few mintes - it was trivial.

Just my thoughts...  :)
Title: Re: how do i import ocx
Post by: picstart on May 05, 2010, 07:50:22 pm
No one has made  more Windows features obsolete than Microsoft. This addiction to making code non portable even between the many Microsoft platforms is in part the encouragement for alternative solutions like Lazarus. Much work is done in Lazarus to mediate the penchant for Microsoft to make portability insecure. Lazarus is probably more portable across Microsoft platforms than anything from Microsoft.It is a bit of an imposition to expect ocx support in Lazarus considering Microsoft is applauding its extinction. With Microsoft Os releases you get to learn a new way to do the same thing. With Lazarus to get to do the same thing on the new OS  without having to re-learn it.
Title: Re: how do i import ocx
Post by: Wodzu on May 06, 2010, 07:30:21 am
It is a bit of an imposition to expect ocx support in Lazarus considering Microsoft is applauding its extinction.

I do not impose to anyone anything. I am not expecting anything from people who are doing something for free. However, I think that the statement about OCX obsolation is untrue.

I was searching on google any information regarding this issue and haven't found a single article saying that ocx is dying.

For example: http://msdn.microsoft.com/en-us/library/aa751968%28v=VS.85%29.aspx.
I think Microsoft would mention it as it does in its articles.

So where did you read about this?
Title: Re: how do i import ocx
Post by: felipemdc on May 06, 2010, 08:26:26 am
How do i put an Active X ocx into a lazarus :-)   :-\

Is your project commercial?
Title: Re: Help with activex (WINDOWS)
Post by: Marc on May 07, 2010, 05:29:36 pm
Reporting your question on different boards won't give you more answers. Please stay on one topic
Title: Is there any Active X suport in Lazarus?
Post by: Lazarususer6789 on May 12, 2010, 01:41:25 pm
Is there any method of using an Active X (OCX) in Lazarus forms?
Title: Re: Is there any Active X suport in Lazarus?
Post by: felipemdc on May 12, 2010, 02:05:36 pm
I think that using COM Automation is a way of using ActiveX non-visual controls:

http://wiki.lazarus.freepascal.org/Office_Automation#Using_COM_Automation_to_interact_with_OpenOffice_and_Microsoft_Office

For using visual controls, did you already find, download and read ActiveX documentation as previously suggested?
Title: Re: Is there any Active X suport in Lazarus?
Post by: Lazarususer6789 on May 12, 2010, 02:33:37 pm
I learned that a program wit Active X uses this info


File name Example "Activex1.ocx"
class id Example "920DFF5F-2EE6-4867-93A5-7BCF15B0F1C2"
what the control inside the ocx is called Example "Activexctl2"

My problem is how do i put this into lazarus
Do i use code or is there a menu?
Title: Re: Is there any Active X suport in Lazarus?
Post by: felipemdc on May 13, 2010, 06:46:52 am
There is no menu.

In Wikipedia you can read some more:

http://en.wikipedia.org/wiki/ActiveX

And there is a link to the source code of a simple ActiveX control in C++, which may also help understand how they work:

http://git.webvm.net/?p=afxsimple;a=tree

And here this C++ code could possibly load an ActiveX by code, although I am not 100% sure:

http://www.codersource.net/mfc/activex-com-dcom/custom-activex-control-in-mfc.aspx

And here an interresting discussion on the subject:

http://us.generation-nt.com/dynamically-loading-an-activex-com-dll-help-25478632.html

I have already said before that what you are trying to achieve isn't easy, so don't expect anyone to show a magic easy way. You will have to research a lot to achieve what you want.
Title: Re: how do i import ocx
Post by: felipemdc on May 13, 2010, 06:59:54 am
If they are obsolete then what is the replacement for them?

ActiveX was a solution for cross-language and cross-technology objects and visual controls.

There is no replacement because the current trend by Microsoft and Apple as well is preventing cross-technology solutions. Microsoft would recommend that you drop all your current code completely and move to .NET instead.

Quote
Personally I think that ActiveX is a nice technology and in the spirit of RAD. Just an example from the real life:

Sure, but I was trying to give a working solution to the question.
Title: Re: How do I import OCX / ActiveX Control
Post by: Lazarususer6789 on May 14, 2010, 03:50:34 pm
I was hoping somebody had made a menu that puts an Active X in the form

Any Way

i was searching in the Lazarus folder and found

C:\lazarus\fpc\2.0.4\units\i386-win32\winunits\activex.o
C:\lazarus\fpc\2.0.4\units\i386-win32\winunits\activex.ppu
C:\lazarus\fpc\2.0.4\units\i386-win32\winunits\libpactivex.a
C:\lazarus\fpc\2.0.4\source\packages\extra\winunits\activex.pp

I think they are what i am looking for but have no idea how to use them
I am new to lazarus so i dont know how to put into project or how to use them
if anyone knows how to use them how do i make this
_______________
|_Form______|X|
|  _________     |
|  | Active X |   |
|  |   Here    |   |
|  |________|   |
|_____________|
i have found an Active x ocx here http://ff24eva.0adz.com/vbp.7z

Title: Re: How do I import OCX / ActiveX Control
Post by: qoxop 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
Title: Re: How do I import OCX / ActiveX Control
Post by: Wodzu on October 14, 2011, 04:35:16 pm
Wow. Finally!
Title: Re: How do I import OCX / ActiveX Control
Post by: zzsczz 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://www.codeproject.com/KB/trace/tracetool.aspx)
http://sourceforge.net/projects/tracetool/ (http://sourceforge.net/projects/tracetool/)


freepascal  can not compile the  delphi version of tracetool sometimes ago
,then  use the activex lib
Title: Re: How do I import OCX / ActiveX Control
Post by: Timewarp 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?
Title: Re: How do I import OCX / ActiveX Control
Post by: Rocky 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.


Title: Re: How do I import OCX / ActiveX Control
Post by: ludob 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
Title: Re: How do I import OCX / ActiveX Control
Post by: Rocky 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: ludob 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: Rocky 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: ludob 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: bambamns 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
Title: Re: How do I import OCX / ActiveX Control
Post by: ludob 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: bambamns 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 ?



Title: Re: How do I import OCX / ActiveX Control
Post by: ludob 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: Rocky 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.
Title: Re: How do I import OCX / ActiveX Control
Post by: bambamns on May 02, 2012, 07:45:01 pm
Thank you ludob , everything is working like it has to bee.

This is 100% substitute for Delphi TWebBrowser (on windows of course).
Title: Re: How do I import OCX / ActiveX Control
Post by: ludob on May 02, 2012, 08:26:58 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.
Do you mean that even a new application (empty form) would crash?
Title: Re: How do I import OCX / ActiveX Control
Post by: Rocky on May 02, 2012, 09:00:47 pm
Yes.

On the Lazarus release, the application starts with a SIGSEGV but can continue. Maybe it's my test computer. I should clean everything and install only the testbuild to see.
Title: Re: How do I import OCX / ActiveX Control
Post by: Timewarp on May 11, 2012, 05:16:29 pm
Thanks for update. This seems much better than using atl.

My Delphi soft uses InternetSecurityManager interface http://msdn.microsoft.com/en-us/library/ms537130(v=vs.85).aspx to block javascript from specified urls. I implemented that to shell.explorer, I can add small sample, if anyone interrested.
Title: Re: How do I import OCX / ActiveX Control
Post by: bambamns on May 27, 2012, 02:44:06 pm
Is there any way to use this ActiveX http://wiki.freepascal.org/LazActiveX#TActiveXContainer_early_binding (http://wiki.freepascal.org/LazActiveX#TActiveXContainer_early_binding) for WinCE (WM 6.5 - WebBrowser) ?
Title: Re: How do I import OCX / ActiveX Control
Post by: Timewarp on June 04, 2012, 08:39:45 pm
Here is two pieces of code, maybe useful to someone else too?!

Need to drop activexcontainer1, edit1, and button1 to form and assign formshow and button1click events.

InternetSecurityManager, ProcessUrlAction: Every action is disallowed, if url contains word "google". (You should notice google autocomplete is disabled)

********

IDocHostUIHandler and CoInternetSetFeatureEnabled

Function TranslateUrl: Try navigate to "google", it goes to http://lazarus.freepascal.org

CoInternetSetFeatureEnabled: Navigation sounds are disabled.
Title: Re: how do i import ocx
Post by: z505 on June 13, 2016, 09:05:02 pm
No one has made  more Windows features obsolete than Microsoft. This addiction to making code non portable even between the many Microsoft platforms is in part the encouragement for alternative solutions like Lazarus.

I know this is a 6 year old post however, can you give some examples of what Microsoft has made obsolete and encouraged to be obsolete? Microsoft is well known for purposely making 10 year old software work on their platforms, they even went in and modified the operating system to work around bugs that other developers created who have nothing to do with microsoft (third party apps).

The whole blog, titled "Old New Thing" describes all the efforts Microsoft has made to make old things work on new things.. (hence blog title)

Quote From Joel Spolsky:
"The Old New Thing is chock-full of detailed technical stories about why certain things are the way they are in Windows, even silly things, which turn out to have very good reasons.

The most impressive things to read on Raymond's weblog are the stories of the incredible efforts the Windows team has made over the years to support backwards compatibility:


I first heard about this from one of the developers of the hit game SimCity, who told me that there was a critical bug in his application: it used memory right after freeing it, a major no-no"
...
..."The testers on the Windows team were going through various popular applications, testing them to make sure they worked OK, but SimCity kept crashing. They reported this to the Windows developers, who disassembled SimCity, stepped through it in a debugger, found the bug, and added special code that checked if SimCity was running, and if it did, ran the memory allocator in a special mode in which you could still use memory after freeing it."


Quote
Much work is done in Lazarus to mediate the penchant for Microsoft to make portability insecure.

One thing I can think of that Microsoft made non portable is old Visual Basic IDE which is no longer in use and people have to change over to .Net.  But if Microsoft really wanted to tick off developers, it would make the Win32 API obsolete, which people still use now... over 20 years later after it was originally developed.  To have an API like win32 last 20 years, and people still create brand new projects using the winapi 20 years later... is pretty impressive with today's throwaway software attitude.

Complaining about microsoft is easy...  but look at all the things that break with apt-get debian or other unix issues.  It's easier to complain about one system, and ignore the problems of your own system. As an example, MacOSX is no better... they made all their old MacOS apps incompatible with the newer OSX.  Easier said than done, to make things all backwards compatible. Sometimes a fresh start is best... Such as deleting all unix and windows systems off the planet and creating a good OS from scratch.  Plan9 tried, and failed...


TinyPortal © 2005-2018