How can you use Delphi to test to see if a website exists?

I have a table for maintaining a list of web addresses; there is a column for the address and a column for tracking whether or not it has been published.  I need to automate scanning the list and testing to see if each address is good.  How can I do this in Delphi 4?

Thanks!
sr-photoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mahdi78Commented:
try this

function IsURLExist(url:string):integer;
var h:tidhttp;
begin
  result:= -1;
  try
    h:=TIdHttp.Create(nil);
    try
      h.HandleRedirects := true;
      h.Head(url);
      result:=h.response.ResponseCode;
    finally
      freeandnil(h);
    end;
  except
  end;
end;
0
Mahdi78Commented:
This is update

function IsURLExist(url:string):boolean;
var h:tidhttp;
begin
  try
    h:=TIdHttp.Create(nil);
    try
      h.HandleRedirects := true;
      h.Head(url);
      result:=h.response.ResponseCode = 200;
    finally
      freeandnil(h);
    end;
  except
  result:= False;
  end;
end;
0
sr-photoAuthor Commented:
I am using Delphi 4; where do I find TIdHttp?  Or what is the Delphi 4 equivalent?  Thanks!
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mahdi78Commented:
It is Indy component
http://www.indyproject.org
0
Mahdi78Commented:
Or try this

uses wininet;

function CheckUrl(url:string):boolean;
var
hSession, hfile: hInternet;
dwindex,dwcodelen :dword;
dwcode:array[1..20] of char;
res : pchar;
begin
Result := false;
hSession := InternetOpen('InetURL:/1.0',INTERNET_OPEN_TYPE_PRECONFIG,nil, nil, 0);
if assigned(hsession) then
  begin
  hfile := InternetOpenUrl( hsession, pchar(url), nil, 0, INTERNET_FLAG_RELOAD, 0);
  dwIndex := 0;
  dwCodeLen := 10;
  HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
  res := pchar(@dwcode);
  result:= (res ='200') or (res ='302');
  if assigned(hfile) then InternetCloseHandle(hfile);
  InternetCloseHandle(hsession);
  end;

end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sr-photoAuthor Commented:
spot on!  thanks for the extra effort, it is really appreciated!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.