Kali ini saya akan ngebahas tentang koneksi, kelihatan hal yang sepele tapi bisa berarti penting jika kita membuat aplikasi berbasis client server, nah ini ada sedikit tips untuk membaca koneksi internet dengan menggunakan delphi.
source code ini bisa dicoba:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
function Koneksi: boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses wininet;
{$R *.dfm}
Function TForm1.Koneksi :boolean;
var
flags: dword;
begin
Result := InternetGetConnectedState(@flags, 0);
if Result then
begin
if (flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then
begin
Edit1.Text := 'Modem';
end;
if (flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
begin
Edit1.Text := 'LAN';
end;
if (flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then
begin
Edit1.Text := 'Proxy';
end;
if (flags and INTERNET_CONNECTION_MODEM_BUSY)=INTERNET_CONNECTION_MODEM_BUSY then
begin
Edit1.Text := 'Modem Busy';
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Koneksi;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
function Koneksi: boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses wininet;
{$R *.dfm}
Function TForm1.Koneksi :boolean;
var
flags: dword;
begin
Result := InternetGetConnectedState(@flags, 0);
if Result then
begin
if (flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then
begin
Edit1.Text := 'Modem';
end;
if (flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
begin
Edit1.Text := 'LAN';
end;
if (flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then
begin
Edit1.Text := 'Proxy';
end;
if (flags and INTERNET_CONNECTION_MODEM_BUSY)=INTERNET_CONNECTION_MODEM_BUSY then
begin
Edit1.Text := 'Modem Busy';
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Koneksi;
end;
berikut saya print screen aplikasinya :
tinggal klik button koneksi maka koneksi yang anda gunakan akan terbaca, seperti pada gambar dibawah ini:
Tidak ada komentar:
Posting Komentar