Link to home
Start Free TrialLog in
Avatar of Clubreseau
Clubreseau

asked on

Delphi Loop with IDHTTP

I load a List of website in Memo1 and use this code to find all webpage who in the source as astrology or ASTROLOGY i use this and it very slow someone have a better idea to make it faster ?

procedure TForm1.Button7Click(Sender: TObject);
 var
  S1: TStringList;
i: Integer;
 position : Integer;
  begin
   S1 := TStringList.Create;
    try
     for i:=0 to Memo1.Lines.Count  do
       begin
         try
          S1.Clear;
            label4.Caption:=(IntToStr(i));
               memo1.lines[i] := StringReplace( memo1.lines[i],'http://','',[rfReplaceAll]);
                 S1.Add(IdHttp1.Get('http://'+memo1.Lines[i]));
                     except on e:exception do
S1.Clear;
 end;
  position := AnsiPos('astrology', S1.text);
   if position = 0 then
    else
     memo2.Lines.Add(memo1.Lines[i]);
       label1.Caption:=(IntToStr(memo2.Lines.Count -0));

  position := AnsiPos('ASTROLOGY', S1.text);
   if position = 0 then
    else
     memo2.Lines.Add(memo1.Lines[i]);
      label1.Caption:=(IntToStr(memo2.Lines.Count -0));
        end;

finally
 AssignFile(myFile, 'URL.dat');
  ReWrite(myFile);
   WriteLn(myFile, memo2.text);
    CloseFile(myFile);
      end;
       end;

Thank You
Avatar of DropZone
DropZone
Flag of United States of America image

Can you give an explanation of what it should do?  Perhaps there's a better approach.

      -dZ.
ASKER CERTIFIED SOLUTION
Avatar of DropZone
DropZone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S. You do not need to check for exceptions if you clean up your code to not perform errors.  For instance, your loop starts from 0 to Memo1.Lines.Count, which is one more than the number of items.  Removing unecessary Try/Except makes code faster.

     -dZ.