Bagaimana mengetahui jenis koneksi Internet menggunakan delphi

Minggu, Juni 22, 2008 | | Comments

Pada pemrograman adakalanya kita membutuhkan pengecekan terhadap koneksi internet, antara lain mengecek update terbaru aplikasi via internet, informasi jenis koneksi internet yang digunakan dan sebagainya. Berikut contoh source code menggunakan delphi :

USES
WinInet;
..
..

function InternetConnected: Boolean;
CONST
// local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = 1;
// local system uses a local area network to connect to the

Internet.
INTERNET_CONNECTION_LAN = 2;
// local system uses a proxy server to connect to the

Internet.
INTERNET_CONNECTION_PROXY = 4;
// local system's modem is busy with a non-Internet

connection.
INTERNET_CONNECTION_MODEM_BUSY = 8;

VAR
dwConnectionTypes : DWORD;
BEGIN
dwConnectionTypes :=
INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
Result := InternetGetConnectedState(@dwConnectionTypes,0);
END;

Contoh penggunaan source code di atas :


Selamat Mencoba !

function TForm1.Connected(const flag : DWORD) : boolean;
var
flags : PDWORD;
begin
New(flags);
try
flags^ := flag;
InternetGetConnectedState(flags, 0);
finally
Dispose(flags);
end;
result := (flags^ and flag) = flag;
end;

eg.

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Clear;
// modem connection
if Connected(INTERNET_CONNECTION_MODEM) then
Memo1.Lines.Add('Modem');
if Connected(INTERNET_CONNECTION_MODEM_BUSY) then
Memo1.Lines.Add('Modem is busy');
// lan connection
if Connected(INTERNET_CONNECTION_LAN) then
Memo1.Lines.Add('Lan');
if Connected(INTERNET_CONNECTION_PROXY) then
Memo1.Lines.Add('Proxy');
end;


Referensi : Delphi3000.com



Source : ai-kom.blogspot.com



Technorati Tags: ,,