I am developing an application that pulls some data from a DB. Based on this data it runs a search on Google and then stores the text of the page I get from Google in a string.
I have the following classes:
Code: Select all
ISourceContainer = interface(ICefStringVisitor)
function Source: ustring;
end;
TSourceContainer = class(TCefStringVisitorOwn, ISourceContainer)
private
FSource: string;
protected
procedure Visit(const str: ustring); override;
public
function Source: ustring;
end;
TMainForm = class(TForm)
Procedure TMainForm.ChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
private
{ Private declarations }
FSourceContainer: ISourceContainer;
end;
Code: Select all
procedure TMainForm.ChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; httpStatusCode: Integer);
var s:string;
begin
if frame = nil then
exit;
if httpStatusCode = 200 then
begin
frame.GetText(FSourceContainer);//text is retrieved here
s:=FSourceContainer.Source;//text is stored in a string
end;
end;
{ TSourceContainer }
function TSourceContainer.Source: ustring;
begin
Result := FSource;
end;
procedure TSourceContainer.Visit(const str: ustring);
begin
FSource := str;
end;
Is there a way to get the text of the webpage without firing ChromiumLoadEnd twice? What is the best approach in these cases ?
Many thanks
Alberto