Solved

Am I connected to the Internet?

Posted on 2002-03-26
3
152 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month3 days, 18 hours left to enroll

630 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