📄 mainformpas.pas
字号:
unit mainformpas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, IdBaseComponent, IdComponent, IdTCPServer,
mytype, myconst, DB, ADODB;
type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
online_ListView: TListView;
Button1: TButton;
Button2: TButton;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
procedure IdTCPServer1Disconnect(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mainctrl:Tctrl;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with online_listview.Items.Add do
begin
caption:=inttostr(index);
subitems.Add('用户名');
SubItems.add('地址');
SubItems.add('日期');
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
label2.Caption:=inttostr(high(mainctrl.online)+1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
mainctrl:=Tctrl.Create;
InitializeCriticalSection(mainctrl.cs);
mainctrl.onlineview:=online_listview;
mainctrl.idtcpserver:=idtcpserver1;
mainctrl.adoquery:=adoquery1;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
userdata: Ruserdata;
ctext:Rcommandtext;
mestext:Rtextdata;
i,j:integer;
st:string;
begin
athread.Connection.ReadBuffer(ctext,sizeof(ctext));
case ctext.command of
Clogin:begin
athread.Connection.ReadBuffer(userdata,sizeof(userdata));
st:=mainctrl.login(userdata);
if st='success' then
begin
athread.connection.WriteLn(st);
userdata.IP:=athread.Connection.Socket.Binding.peerip;
userdata.post:=athread.Connection.Socket.Binding.peerport;
userdata.AThread:=athread;
mainctrl.addonline(userdata);
mainctrl.sendallonline(athread);
end
else athread.Connection.WriteLn(st);
end;
Creg:begin
athread.Connection.ReadBuffer(userdata,sizeof(userdata));
st:=mainctrl.reg(userdata);
athread.Connection.WriteLn(st);
end;
Csendtext:begin
athread.Connection.ReadBuffer(mestext,sizeof(mestext));
mainctrl.sendtext(ctext,mestext);
end;
Cmodiwhatdoing:begin
athread.Connection.ReadBuffer(userdata,sizeof(userdata));
mainctrl.modiwhatdoing(ctext,userdata);
end;
Cstart:begin
//接收务战方用户的信息。
athread.Connection.ReadBuffer(userdata,sizeof(userdata));
userdata.athread.Connection.WriteBuffer(ctext,sizeof(ctext));
//以athread找出自己的信息然后发送给对方
for i:=0 to high(mainctrl.online) do
begin
if mainctrl.online[i].athread.handle=AThread.handle then
begin
userdata.athread.Connection.WriteBuffer(mainctrl.online[i],sizeof(mainctrl.online[i]));
end;
end;
//修改备战方的关态。
ctext.command:=Cmodiwhatdoing;
ctext.num:=2;
mainctrl.modiwhatdoing(ctext,userdata);
end;
Cmodiuser:begin
athread.Connection.ReadBuffer(userdata,sizeof(userdata));
mainctrl.modifeng(ctext,userdata);
end;
end;//case
end;
procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
mainctrl.deleonline(athread);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -