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://','',[rfReplac eAll]);
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.Line s[i]);
label1.Caption:=(IntToStr( memo2.Line s.Count -0));
position := AnsiPos('ASTROLOGY', S1.text);
if position = 0 then
else
memo2.Lines.Add(memo1.Line s[i]);
label1.Caption:=(IntToStr( memo2.Line s.Count -0));
end;
finally
AssignFile(myFile, 'URL.dat');
ReWrite(myFile);
WriteLn(myFile, memo2.text);
CloseFile(myFile);
end;
end;
Thank You
procedure TForm1.Button7Click(Sender
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(
memo1.lines[i] := StringReplace( memo1.lines[i],'http://','',[rfReplac
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.Line
label1.Caption:=(IntToStr(
position := AnsiPos('ASTROLOGY', S1.text);
if position = 0 then
else
memo2.Lines.Add(memo1.Line
label1.Caption:=(IntToStr(
end;
finally
AssignFile(myFile, 'URL.dat');
ReWrite(myFile);
WriteLn(myFile, memo2.text);
CloseFile(myFile);
end;
end;
Thank You
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
-dZ.
-dZ.