Solved

Am I connected to the Internet?

Posted on 2002-03-26
3
146 Views
Last Modified: 2010-04-04
Using Delphi 3...

How can my D3 application detect whether the user is currently connected to the Internet or not?
0
Comment
Question by:Kapusta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6897994
What type of D3 are you using?  Developer / Profession / Client Server?  Do you have any internet controls?

Stu
0
 

Author Comment

by:Kapusta
ID: 6898013
I am using Delphi Professional.  As far as components, I have the Internet Mail Suite 1.x by Artchil Gogava.
0
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 6898103
Hi Kapusta,

Here is some code for you.

const
  INTERNET_CONNECTION_MODEM           = 1;
  INTERNET_CONNECTION_LAN             = 2;
  INTERNET_CONNECTION_PROXY           = 4;
  INTERNET_CONNECTION_MODEM_BUSY      = 8;

function InternetGetConnectedState(lpdwFlags: LPDWORD;
  dwReserved: DWORD): BOOL; stdcall; external 'WININET.DLL';

function  _IsConnectedToInternet: Boolean;
var
  dwConnectionTypes: Integer;
begin
  try
    dwConnectionTypes := {INTERNET_CONNECTION_MODEM +}
                         INTERNET_CONNECTION_LAN +
                         INTERNET_CONNECTION_PROXY;
    if InternetGetConnectedState(@dwConnectionTypes, 0) then
      Result := true
    else
      Result := false;
  except
    Result := false;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
   if _IsConnectedToInternet then
     ShowMessage('Yes')
   else
     ShowMessage('No');
end;

This works fine, however it doesn't detect an instant disconnect/connect.  I've found I have to retry it a couple of times before it realises that you're no longer connected to the net (this is the case with Lan anyway, not sure about modem).  This is a Windows thing, not a Delphi/Code thing.

Let me know if you need anymore help,

Cheers,

Stu
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question