Create a procedure to handle the OnTextResultAvailable event and assign it to TChromiumWindow.ChromiumBrowser.OnTextResultAvailable.
Then call TChromiumWindow.ChromiumBrowser.RetrieveHTML and you will receive the HTML in the procedure you created previously.
TChromiumWindow was created to add very simple browsers to apps.
If you need to use some functions or events it's much easier to use the TChromium and TCEFWindowParent components.
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
How to get HTML code from TChromiumWindow
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to get HTML code from TChromiumWindow
The MiniBrowser demo has all the code to copy the HTML code in the clipboard.Askerman wrote: Fri Mar 23, 2018 8:23 pm I have error [dcc32 Error] Main.pas(129): E2009 Incompatible types: 'Parameter lists differ' on line "ChromiumWindow1.ChromiumBrowser.OnTextResultAvailable := GetHtml;". What i should to do?
My code :Code: Select all
... type TForm1 = class (TForm) ChromiumWindow1 : TChromiumWindow; procedure FormCreate (Sender : TObject); private {Private declarations} public procedure GetHtml (Sender : TObject; aText : String); end; ... procedure TForm1.FormCreate (Sender : TObject); begin ChromiumWindow1.CreateBrowser; ChromiumWindow1.ChromiumBrowser.OnTextResultAvailable := GetHtml; end; procedure TForm1.GetHtml (Sender : TObject; aText : String); begin //My code; end; ...
Declare the GetHTML like this :
Code: Select all
procedure GetHtml(Sender: TObject; const aText: string);
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to get HTML code from TChromiumWindow
The MiniBrowser demo has all the code to copy the HTML code in the clipboard.beryindo wrote: Sat Mar 24, 2018 1:43 am RetrieveHTML is it equal to view page source ?
I am try this code for CEFWindowsparent and TChromium. But not workCode: Select all
procedure TForm1.Chromium1TextResultAvailable(Sender: TObject; const aText: string); begin Chromium1.RetrieveHTML(aText); MemoRespon.Text := aText; end;
You have to call RetrieveHTML outside the Chromium1TextResultAvailable procedure.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to get HTML code from TChromiumWindow
Hi,
To get the HTML you need to follow these steps :
It saves the aText parameter in the clipboard but you can save it wherever you need.
To get the HTML you need to follow these steps :
- Imlement the TChromium.OnTextResultAvailable event because the HTML will be received in the 'aText parameter from this is event.
- Call TChromium.RetrieveHTML when the document is loaded.
- After a few milliseconds the TChromium.OnTextResultAvailable event is triggered and you can copy the aText parameter with the HTML.
It saves the aText parameter in the clipboard but you can save it wherever you need.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to get HTML code from TChromiumWindow
Visit this page :
https://github.com/salvadordf/CEF4Delph ... rowser.pas
Scroll to the line 934 for the CopyHTMLMsg code and line 752 for the Chromium1TextResultAvailable code.
https://github.com/salvadordf/CEF4Delph ... rowser.pas
Scroll to the line 934 for the CopyHTMLMsg code and line 752 for the Chromium1TextResultAvailable code.