Napisalem prosta przegladarke z komponentwm WebBrowser, jak zrobic aby po wcisnieciu buttona wyszukalo mi na aktualnie otwartej stronie tekstu ktory wpisalem do edit1 i jezeli go znajdzie to niech pokaze komunikat.
OK!
Cos znalazlem i dziala:
procedure TForm1.SearchAndHighlightText(aText: string);
var
i: Integer;
begin
for i := 0 to WebBrowser1.OleObject.Document.All.Length - 1 do
begin
if Pos(aText, WebBrowser1.OleObject.Document.All.Item(i).InnerText) <> 0 then
begin
WebBrowser1.OleObject.Document.All.Item(i).Style.Color := '#FFFF00';
WebBrowser1.OleObject.Document.All.Item(i).ScrollIntoView(True);
label1.Caption := 'POTWIERDZ';
end;
end;
end;
procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
SearchAndHighlightText(Edit3.Text);
end;
To dziala tylko w tedy gdy strona nie posiada ramek (lub posiada jedna)
Jak to przeksztalcic zeby wyszukiwalo informacji w ramce zerowej?
wiem ze gdzies trzeba dodac ...frames.item[0]... lub jakos tak
tu mam przyklad ktory sprawdza adres ramki zerowej:
procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
Listbox1.Clear;
//if frames available
if Webbrowser1.OleObject.Document.Frames.Length <> 0 then
begin
//walk through all frames and get the url
//to the Listbox
Listbox1.Items.Add(Webbrowser1.OleObject.Document.Frames.item(0).Document.URL);
end;
end;
Pisze z głowy - może nie działać!!
procedure TForm1.SearchAndHighlightText(aText: string);
var
a: Integer;
begin
for a := 0 to WebBrowser1.OleObject.Document.Frame.Length - 1 do
begin
if Pos(aText, WebBrowser1.OleObject.Document.Frame.Item(a).InnerText) <> 0 then
begin
WebBrowser1.OleObject.Document.frame.Item(a).Style.Color := '#FFFF00';
WebBrowser1.OleObject.Document.frame.Item(a).ScrollIntoView(True);
label1.Caption := 'POTWIERDZ';
end;
end;
end;
Nie dziala :-(
Program sie odpala ale po wcisnieciu wyszukiwania pada :-(
Stawiam zgrzewke piwa temu kto to zrobi :-)
A dało by się coś innego, bo nie lubie piwa, no jak już to karmi ;-)
Na krótszą droge może to:
uses
ActiveX;
procedure WB_ShowFindDialog(AWebbrowser: TWebbrowser);
const
CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
HTMLID_FIND = 1;
HTMLID_VIEWSOURCE = 2;
HTMLID_OPTIONS = 3;
var
CmdTarget : IOleCommandTarget;
vaIn, vaOut: OleVariant;
PtrGUID: PGUID;
begin
New(PtrGUID);
PtrGUID^ := CGID_WebBrowser;
if AWebbrowser.Document <> nil then
try
AWebbrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget);
if CmdTarget <> nil then
try
CmdTarget.Exec(PtrGUID, HTMLID_FIND, 0, vaIn, vaOut);
finally
CmdTarget._Release;
end;
except
// Nothing
end;
Dispose(PtrGUID);
end;
// Example:
// Navigate to a page
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('www.swissdelphicenter.com');
end;
// Show the Find Dialog
procedure TForm1.Button2Click(Sender: TObject);
begin
WB_ShowFindDialog(WebBrowser1);
end;
Nie mogłem tego sprawdzić, ale znalazłem to po częci w internecie:
procedure TForm1.SearchAndHighlightText(aText: string);
var
a: Integer;
begin
for a := 0 to WebBrowser1.OleObject.Document.Frames.Length - 1 do
begin
if Pos(aText, WebBrowser1.OleObject.Document.frames(a).Document.documentElement.innertext) <> 0 then
begin
WebBrowser1.OleObject.Document.frames.Item(a).Document.documentElement.Style.Color := '#FFFF00';
WebBrowser1.OleObject.Document.frames.Item(a).Document.documentElement.ScrollIntoView(True);
label1.Caption := 'POTWIERDZ';
end;
end;
end;