//对照程序,添加相应的控件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Psock, NMMSG;
type
TForm1 = class(TForm)
NMMsg1: TNMMsg;
NMMSGServ1: TNMMSGServ;
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
Edit3: TEdit;
bntsend: TButton;
StatusBar1: TStatusBar;
procedure bntsendClick(Sender: TObject);
procedure NMMsg1MessageSent(Sender: TObject);
procedure NMMsg1Connect(Sender: TObject);
procedure NMMsg1ConnectionFailed(Sender: TObject);
procedure NMMsg1Disconnect(Sender: TObject);
procedure NMMsg1HostResolved(Sender: TComponent);
procedure NMMsg1Status(Sender: TComponent; Status: String);
procedure NMMsg1InvalidHost(var Handled: Boolean);
procedure NMMSGServ1MSG(Sender: TComponent; const sFrom, sMsg: String);
procedure NMMSGServ1ClientContact(Sender: TObject);
procedure NMMSGServ1Status(Sender: TComponent; Status: String);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.bntsendClick(Sender: TObject);
begin
NMMsg1.Host :=edit3.text;
NMMsg1.FromName :=edit2.text;
NMMsg1.PostIt (edit1.text);//发送信息
end;
procedure TForm1.NMMsg1MessageSent(Sender: TObject);
begin
showMessage('Message sent!');
end;
procedure TForm1.NMMsg1Connect(Sender: TObject);
begin
StatusBar1.SimpleText :='连接成功connection';
end;
procedure TForm1.NMMsg1ConnectionFailed(Sender: TObject);
begin
showmessage('Connection Failed连接失败');
end;
procedure TForm1.NMMsg1Disconnect(Sender: TObject);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :='Disconnected';
end;
procedure TForm1.NMMsg1HostResolved(Sender: TComponent);
begin
StatusBar1.SimpleText :='Host Resolved';
end;
procedure TForm1.NMMsg1Status(Sender: TComponent; Status: String);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :=status;
end;
procedure TForm1.NMMsg1InvalidHost(var Handled: Boolean);
var
TmpStr:string;
begin
If InputQuery('Invalid Host!','Specify a new host:',TmpStr)then
begin
NMMsg1.Host :=TmpStr;
Handled:=True;
end;
end;
procedure TForm1.NMMSGServ1MSG(Sender: TComponent; const sFrom,
sMsg: String);
begin
Memo1.Lines.Add ('Message From:'+sFrom);//发送者姓名
Memo1.lines.add(#9+'From IP:'+NMMSGServ1.remoteIP);//ip地址信息
memo1.lines.add(#9+'Message:'+sMsg);//实际信息
end;
procedure TForm1.NMMSGServ1ClientContact(Sender: TObject);
begin
NMMsgServ1.ReportLevel :=Status_Basic;
NMMsgServ1.TimeOut :=90000;
StatusBar1.SimpleText :='Client connected';
end;
procedure TForm1.NMMSGServ1Status(Sender: TComponent; Status: String);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :=status;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.text:='';
edit2.text:='';
edit3.text:='';
memo1.text:='';
end;
end.