Lazarus

Programming => Operating Systems => Windows => Topic started by: TyneBridges on December 24, 2020, 08:19:24 pm

Title: Get details from Internet Explorer
Post by: TyneBridges on December 24, 2020, 08:19:24 pm
Can anyone advise me what is the simplest way of monitoring the current URL and page title in Internet Explorer (already running) using Lazarus?

I have old code from Delphi where I did this with a TWebBrowser but it seems it's not easy to get this to work in Lazarus, and I need to update the program to work with 64 bit processes. I've looked at https://wiki.freepascal.org/Webbrowser and https://wiki.lazarus.freepascal.org/LazActiveX. The approach in "Creating visual ActiveX components from type libraries or objects" looks like what I need with late binding, but I don't understand how to include an Internet Explorer ActiveX object in Lazarus or whether I can get the necessary information from my old code (written many years ago).

(I realise IE is an obsolescent browser; a completely different method is needed to capture Chrome logs but at least its use of a SQLite database is well enough documented for that to work.)

Thank you.

Title: Re: Get details from Internet Explorer
Post by: TyneBridges on January 03, 2021, 08:21:32 pm
On re-reading and checking, late binding means too many unknowns for me. In theory I can do this with early binding (full interfaces known to the PC) by importing the TWebBrowser ActiveX control. Unfortunately this control doesn't appear in the lists when I click "Import Type Library" from the Tools menu. Does anyone know why this is?

Thanks.
Title: Re: Get details from Internet Explorer
Post by: MarkMLl on January 03, 2021, 09:06:32 pm
What exactly are you trying to "monitor"? You might be using a steam hammer to crack a nut.

MarkMLl
Title: Re: Get details from Internet Explorer
Post by: marcov on January 03, 2021, 10:02:15 pm
Afaik twebbrowser is a Delphi shell around the imported activex object, not the object itself.
Title: Re: Get details from Internet Explorer
Post by: TyneBridges on January 04, 2021, 01:35:35 pm
What exactly are you trying to "monitor"? You might be using a steam hammer to crack a nut.

MarkMLl

Thanks. I may have been on the wrong track, confusing the TWebBrowser with a different facility in the program.

I want to get each URL and page title in Internet Explorer, which I could do in Delphi using the following code. (Sw is declared as IShellWindows) This links to Internet Explorer and extracts the page title (T) and address (A) as a string. It still works but I'd like to update it to 64 bit and have only an old 32 bit version of Delphi.

Code: Pascal  [Select][+][-]
  1.    
  2. WB: IWebBrowser2;
  3. begin
  4.     for X:= 0 to SW.Count - 1 do
  5.     begin
  6.          WB:= Sw.Item(x) as IWebBrowser2;
  7.          if WB = Nil then
  8.             AT:= ''
  9.          else begin
  10.              AT:= WB.LocationURL + '|' + WB.LocationName;
  11.              If (Uppercase(Copy(AT, 1, 4)) = 'HTTP') or (Uppercase(Copy(AT, 1, 4)) = 'FILE') then
  12.  
Title: Re: Get details from Internet Explorer
Post by: TyneBridges on January 06, 2021, 10:22:51 am
On close inspection of the old Delphi project I see it doesn't include (so doesn't need) a TWebBrowser control. However, I do need the units ShDocVw_Tlb and ActiveX, or their Lazarus equivalents and my converted code currently doesn't compile with these references. Any tips on how I can proceed?

Thanks.
Title: Re: Get details from Internet Explorer
Post by: PascalDragon on January 06, 2021, 11:29:01 am
The ActiveX unit is already provided with FPC.

For the ShDocVw_Tlb unit you can either use the Delphi one (just add {$ifdef fpc}{$mode delphi}{$endif} at the top) or you can let Lazarus' type library importer import it:

 
Now you should be able to compile your code.
Title: Re: Get details from Internet Explorer
Post by: TyneBridges on January 08, 2021, 10:23:28 am
The ActiveX unit is already provided with FPC.

For the ShDocVw_Tlb unit you can either use the Delphi one (just add {$ifdef fpc}{$mode delphi}{$endif} at the top) or you can let Lazarus' type library importer import it:

  • install LazActiveX
  • go to Tools -> Import Type Library...
  • select Microsoft Internet Controls (doesn't matter which tab you choose) and click Ok
  • Lazarus will open a new unit ShDocVw_1_1_Tlb; it doesn't look like it, but you need to save it (you can rename it to ShDocVw_Tlb then if you want to)
 
Now you should be able to compile your code.

Thanks - that looks just like the information I need. I think the converter did import ShDocVw_TLb from my Delphi project but, for whatever reason, it wasn't then recognised correctly by the compiler. I will remove it and try your procedure.
Title: Re: Get details from Internet Explorer
Post by: TyneBridges on January 08, 2021, 05:57:51 pm
Thanks. After following PascalDragon's instruction, more of my converted code now is compiling but I still get an error on the following. I've tried changing the declaration TrayIconData: TNotifyIconData; to TrayIconData: TNotifyIconDataW; but I still get the error Identifier not found: Wnd.

Do I need to change a reference somewhere to a pointer?

Code: Pascal  [Select][+][-]
  1.    
  2. Try
  3.         With TrayIconData do
  4.         begin
  5.             cbSize:= SizeOf(TrayIconData);
  6.             Wnd:= Handle;                                  
  7.  
Title: Re: Get details from Internet Explorer
Post by: marcov on January 08, 2021, 05:59:58 pm
ctrl-click the  "TNotifyIconDataW" type and the ide will jump to the definition. Probably it is hwnd
TinyPortal © 2005-2018