///////////////////////////////////////////////////////////////////////////
// //
// Copyright ?1997-1998, NetMasters, L.L.C //
// - All rights reserved worldwide. - //
// Portions may be Copyright ?Inprise. //
// //
// Message Client/Server Demo Unit 1: (UNIT1.PAS) //
// //
// DESCRIPTION: //
// //
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY //
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE //
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR //
// PURPOSE. //
// //
///////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// //
///////////////////////////////////////////////////////////////////////////
unit msgdem;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Psock, NMMSG, ComCtrls, ScktComp;
type
TForm1 = class(TForm)
Panel1: TPanel;
Memo1: TMemo;
Edit1: TEdit;
NMMsg1: TNMMsg;
NMMSGServ1: TNMMSGServ;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Edit3: TEdit;
StatusBar1: TStatusBar;
Label3: TLabel;
btnSend: TButton;
ListBox1: TListBox;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Splitter1: TSplitter;
procedure NMMSGServ1MSG(Sender: TComponent; const sFrom, sMsg: String);
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 NMMSGServ1ClientContact(Sender: TObject);
procedure NMMSGServ1Status(Sender: TComponent; Status: String);
procedure btnSendClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.NMMSGServ1MSG(Sender: TComponent; const sFrom,
sMsg: String);
begin
Memo1.Lines.Add(sFrom+'发送:'+sMsg);
{Memo1.Lines.Add('Message From: '+sFrom);
Memo1.Lines.Add(#9+'From IP: '+NMMSGServ1.RemoteIP);
Memo1.Lines.Add(#9+'Message: '+sMsg);
Memo1.Lines.Add(#9+'Message: '+NMMSGServ1.Host);}
btnSend.Enabled := True;
end;
procedure TForm1.NMMsg1MessageSent(Sender: TObject);
begin
//ShowMessage('Message sent!');
end;
procedure TForm1.NMMsg1Connect(Sender: TObject);
begin
StatusBar1.SimpleText := '已连接';
end;
procedure TForm1.NMMsg1ConnectionFailed(Sender: TObject);
begin
ShowMessage('连接失败!');
end;
procedure TForm1.NMMsg1Disconnect(Sender: TObject);
begin
If StatusBar1 <> nil then
StatusBar1.SimpleText := '断开';
end;
procedure TForm1.NMMsg1HostResolved(Sender: TComponent);
begin
StatusBar1.SimpleText := '当机';
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('主机不存在!', '指定一个新的主机:', TmpStr) then
Begin
NMMsg1.Host := TmpStr;
Handled := TRUE;
End;
end;
procedure TForm1.NMMSGServ1ClientContact(Sender: TObject);
begin
NMMsgServ1.ReportLevel := Status_Basic;
NMMsgServ1.TimeOut := 90000;
StatusBar1.SimpleText := '客户连接';
end;
procedure TForm1.NMMSGServ1Status(Sender: TComponent; Status: String);
begin
If StatusBar1 <> nil then
StatusBar1.SimpleText := status;
end;
procedure TForm1.btnSendClick(Sender: TObject);
begin
NMMsg1.Host := Edit3.Text;
NMMsg1.FromName := Edit2.Text;
NMMsg1.PostIt(Edit1.Text);
btnSend.Enabled := False;
end;
end.