Delphi connection example

Last Updated : May 01, 2020 |

The system password in the call to DLOpen() must be replaced with the actual system password of your unit.

unit Unit1; 
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; 
type TForm1 = class(TForm) Button1: TButton; 
procedure Button1Click(Sender: TObject); 
procedure Button2Click(Sender: TObject); 
private { Private declarations } 
public { Public declarations } 
end; 
var Form1: TForm1; 
implementation uses devlink; 
{$R *.DFM} var hEvent : THANDLE; 
dwCommsEvent : DWORD; 
bStarting: boolean; 
procedure HandleCommsEvent( pbxh : LongInt; 
Comms_status : DWORD; Parm1 : DWORD ); 
stdcall; 
begin case Comms_status of DEVLINK_COMMS_OPERATIONAL, DEVLINK_COMMS_NORESPONSE, DEVLINK_COMMS_REJECTED: begin if bStarting then begin dwCommsEvent := comms_status; SetEvent( hEvent ); 
end; 
end; 
DEVLINK_COMMS_MISSEDPACKETS: begin 
// parm1 indicates the number of packets missed... 
end; 
end; 
end; 
procedure TForm1.Button1Click(Sender: TObject); 
begin bStarting := TRUE; 
hEvent := CreateEvent( nil, FALSE, FALSE, nil ); 
DLOpen( 0, '255.255.255.255', 'systempassword', nil, nil, - HandleCommsEvent ); 
dwCommsEvent := DEVLINK_COMMS_NORESPONSE; 
WaitForSingleObject( hEvent, 10000 ); 
// 10-second timeout bStarting := FALSE; 
if dwCommsEvent = DEVLINK_COMMS_OPERATIONAL then begin ShowMessage('Connected OK'); 
end else begin ShowMessage('Error connecting to IP Office'); 
end; 
end; 
procedure TForm1.Button2Click(Sender: TObject); 
begin DLClose( 0 ); CloseHandle( hEvent ); 
end; 
end