private
_AddrChangeEventHandle: THandle;
procedure CreateNotifyEvent;
public
{ Public-Deklarationen }
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
function NotifyAddrChange(
out Handle: THANDLE;
const Overlapped: OVERLAPPED): DWORD;
stdcall;
external '
Iphlpapi.dll';
procedure TDemoForm.FormCreate(Sender: TObject);
begin
_AddrChangeEventHandle := CreateEvent(
NIL, FALSE, FALSE,
NIL);
CreateNotifyEvent;
end;
procedure TDemoForm.CreateNotifyEvent;
var
NotifyHandle: Cardinal;
Overlapped: _OVERLAPPED;
NotifyResult: Cardinal;
begin
Overlapped.hEvent := _AddrChangeEventHandle;
NotifyResult := NotifyAddrChange(NotifyHandle, Overlapped);
if not ((NotifyResult = NO_ERROR)
or (NotifyResult = ERROR_IO_PENDING))
then
begin
RaiseLastOSError;
end;
end;
procedure TDemoForm.FormDestroy(Sender: TObject);
begin
CloseHandle(_AddrChangeEventHandle);
end;
procedure TDemoForm.Timer1Timer(Sender: TObject);
begin
if (WaitForSingleObject(_AddrChangeEventHandle, 0) = WAIT_OBJECT_0)
then
begin
ShowMessage('
IP wurde geändert.');
CreateNotifyEvent;
end;
end;