Recent

Author Topic: Get details from Internet Explorer  (Read 2590 times)

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Get details from Internet Explorer
« 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.

John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Get details from Internet Explorer
« Reply #1 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.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: Get details from Internet Explorer
« Reply #2 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Get details from Internet Explorer
« Reply #3 on: January 03, 2021, 10:02:15 pm »
Afaik twebbrowser is a Delphi shell around the imported activex object, not the object itself.

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Get details from Internet Explorer
« Reply #4 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.  
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Get details from Internet Explorer
« Reply #5 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.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

PascalDragon

  • Hero Member
  • *****
  • Posts: 5476
  • Compiler Developer
Re: Get details from Internet Explorer
« Reply #6 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:

  • 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.

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Get details from Internet Explorer
« Reply #7 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.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Get details from Internet Explorer
« Reply #8 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.  
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Get details from Internet Explorer
« Reply #9 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