• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

refresh browser intil a word appears then stop.

I found some source code for delphi 5 that I am working on for delphi 7(converting it over), I was wondering, how to get the application to refresh itself intil a specific string is no longer present. Basically, its both for my education as well as for my entertainment(I play neopets alot and get tired on a specific section), It doesnt need to do anything else except refresh itself on a specific page and once these words no longer are displayed it should alert me and stop refreshing. Any easy way of doing this. Code is freely available at planet source code and its the newest browser one. IF someone answers quickly I will buy points and give the person 500 extra points. Thanks.
0
virtex
Asked:
virtex
  • 5
  • 3
1 Solution
 
geobulCommented:
Hi,

Are you talking about TWebBrowser component palced on a form? If yes, does the web page contain frames?

Regards, Geo
0
 
virtexAuthor Commented:
Actually it is a generic system, enclosed below is the source code.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, OleCtrls, SHDocVw, Menus;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    WebBrowser1: TWebBrowser;
    StatusBar1: TStatusBar;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DownloadComplete(Sender: TObject);
    procedure WebBrowser1DownloadBegin(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_Return then
  begin
    WebBrowser1.Navigate(WideString(Edit1.Text));
    Button2.Enabled :=True;
    Button4.Enabled :=True;
    Form1.Caption :=(Edit1.Text);
    StatusBar1.Panels[0].Text :=('Finding Site...');
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  WebBrowser1.Navigate(WideString('http://www.antitrustthemovie.com'));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Webbrowser1.Stop;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  WebBrowser1.GoBack;
  Button3.Enabled :=True;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  WebBrowser1.GoForward;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Navigate(WideString('http://www.antitrustthemovie.com'));
  Button2.Enabled :=False;
  Button3.Enabled :=False;
  Button4.Enabled :=False;
end;

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
  StatusBar1.Panels[0].Text :=('Done.');
end;

procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
  StatusBar1.Panels[0].Text :=('Finding Site...');
end;

end.

I am basically wanting this for neopets on the garage sale area. reason I need it to refresh is because it randomly puts items out there, when there isnt items out there it displays text to the effect of OH NO!! we ran out of items.

I would like to have the page when I click a button and enter text that it should look to not have shown, refresh til it no longer shows that text. This way I can just click the items and not have to be waiting so to speak. This way I learn more about how to do stuff with delphi and at the same time it helps me out. No frames are present.
0
 
geobulCommented:
Ok. I hope the following will help you:

function WebBrowserFindInSource(wb: TWebBrowser; const what: string): boolean;
var
  sl: TStringList;
  DOM: variant;
begin
  result := false;
  sl := TStringList.Create;
  try
    DOM := wb.Document;
    if wb.LocationURL <> '' then begin
      sl.Text := DOM.Body.OuterHTML;
      if Pos(what, sl.Text) > 0 then begin
        result := true;
      end;
    end;
  finally
    sl.Free;
  end;
end;

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
  if WebBrowserFindInSource(WebBrowser1, 'OH NO!!') then begin
      WebBrowser1.Refresh;
  end else begin
     StatusBar1.Panels[0].Text :=('Done.');
  end;
end;

Regards, Geo
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
virtexAuthor Commented:
would it be possible for you to just copy and paste the whole code as it seems I am getting a few errors that I am not familier with.
0
 
virtexAuthor Commented:
I got it to compile correctly but it isnt refreshing the screen. here is my source code.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, OleCtrls, SHDocVw, Menus;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    WebBrowser1: TWebBrowser;
    StatusBar1: TStatusBar;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DownloadComplete(Sender: TObject);
    procedure WebBrowser1DownloadBegin(Sender: TObject);
          private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  sl: TStringList;
  DOM: variant;


implementation

{$R *.DFM}

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_Return then
  begin
    WebBrowser1.Navigate(WideString(Edit1.Text));
    Button2.Enabled :=True;
    Button4.Enabled :=True;
    Form1.Caption :=(Edit1.Text);
    StatusBar1.Panels[0].Text :=('Finding Site...');
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  WebBrowser1.Navigate(WideString('http://www.antitrustthemovie.com'));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Webbrowser1.Stop;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  WebBrowser1.GoBack;
  Button3.Enabled :=True;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  WebBrowser1.GoForward;
end;

function WebBrowserFindInSource(wb: TWebBrowser; const what: string): boolean;
 begin
 result := false;
 sl := TStringList.Create;
 try
   DOM := wb.Document;
   if wb.LocationURL <> '' then begin
     sl.Text := DOM.Body.OuterHTML;
     if Pos(what, sl.Text) > 0 then begin
       result := true;
     end;
   end;
 finally
   sl.Free;
   end;
 end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Navigate(WideString('http://www.antitrustthemovie.com'));
  Button2.Enabled :=False;
  Button3.Enabled :=False;
  Button4.Enabled :=False;
end;

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
 if WebBrowserFindInSource(WebBrowser1, 'we just ran') then begin
     WebBrowser1.Refresh;
 end else begin
    StatusBar1.Panels[0].Text :=('Done.');
end;
end;

procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
  StatusBar1.Panels[0].Text :=('Finding Site...');
end;

end.

0
 
virtexAuthor Commented:
the site I am going to is http://www.neopets.com/winter/igloo.phtml then I click the here link. I would think it should work. There isnt any reason why it isnt other than code..

Much thanks!
0
 
virtexAuthor Commented:
never mind. I fixed it. Thanks.
Awarding points and concidering this closed.

Will send you the 500 as soon as I get back home(this evenning)
0
 
geobulCommented:
Hi,

I'm glad you managed to make it work yourself. I went to bed after I posted my proposal ;-)

About additional points - according to site regulations one question can be awarded with a maximum of 500 points. So, if you want to give additional points to me then they cannot exceed 325.

Regards, Geo
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now