| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 605 人关注过本帖
标题:求助:代码注释
取消只看楼主 加入收藏
天痕
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-29
收藏
 问题点数:0 回复次数:0 
求助:代码注释

在一本书上找到的一个聊天工具,请尽可能详细的注解下。 谢谢各位了

服务器端:

procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
var
newitem:TListItem;
ii,jj:Integer;
user,usercur:string;
begin
newitem:=ListView1.Items.Insert(ListView1.Items.Count);
newitem.Caption:='Client:'+IntToStr(ListView1.Items.Count);
newitem.SubItems.Add(Socket.RemoteHost);
newitem.SubItems.Add(Socket.RemoteAddress);
newitem.SubItems.Add(IntToStr(Socket.RemotePort));
//ListView1.AlphaSort();
ListView1.Items.Item[ListView1.Items.Count-1].Selected:=true;
Display('连接到主机:'+Socket.RemoteAddress+' 成功');
ii:=ListView1.ItemIndex;
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
ListView1.Items[ii].Caption+'加入进来!');
user := listview1.Items[ii].Caption + '^' +
listview1.Items[ii].SubItems[0] + '^'
+ listview1.Items[ii].SubItems[1] + '^'
+ listview1.Items[ii].SubItems[2];
for jj := 0 to listview1.Items.Count - 1 do
begin
serversocket1.Socket.Connections[jj].SendText('增加用户@#!^' +
user + '^');
end;
for jj := 0 to listview1.Items.Count - 2 do
begin
user := listview1.Items[jj].Caption + '^' +
listview1.Items[jj].SubItems[0] + '^'
+ listview1.Items[jj].SubItems[1] + '^'
+ listview1.Items[jj].SubItems[2];
serversocket1.Socket.Connections[ii].SendText('增加用户@#!^' +
user + '^');
end;
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var
ii,jj:integer;
User:String;
begin
for ii:=0 to ListView1.Items.Count-1 do begin
if ListView1.Items.Item[ii].SubItems.Strings[2]=IntToStr(Socket.RemotePort) then begin
for jj:=0 to ListView1.Items.Count -1 do begin
user:=ListView1.Items[ii].Caption+'^'+ListView1.Items[ii].subitems[0]+'^'+
ListView1.Items[ii].SubItems[1]+'^'+ListView1.Items[ii].subitems[2];
ServerSocket1.Socket.Connections[jj].SendText('删除用户@#!^'+User+'^');
end;
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
ListView1.Items[ii].Caption+'走了!');
ListView1.Items.Item[ii].Delete();
Display(Socket.RemoteHost+'走了');


end;
end;
if ListView1.Items.Count=0 then begin
Display('获取信息......');
end;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
tmpstr,User:string;
ii,jj:integer;
ListItem:TListItem;
exist:bool;
begin
exist:=False;
tmpstr:=Socket.ReceiveText;
if getmaskstring(tmpstr,'^',1)='交谈@#!' then begin
for jj:=0 to ListView1.Items.Count -1 do begin
user:=getmaskstring(tmpstr,'^',2);
ServerSocket1.Socket.Connections[jj].SendText('交谈@#!^'+User+'^');
end;
Richedit1.Lines.Add(getmaskstring(tmpstr,'^',2));
end;
if getmaskstring(tmpstr,'^',1)='昵称@#!' then begin
for ii:=0 to ListView1.Items.Count-1 do begin
if Socket.RemotePort=StrToInt(ListView1.Items[ii].SubItems[2])
then begin
exist:=true;
if getmaskstring(tmpstr,'^',2)<>ListView1.Items[ii].Caption then
begin
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
ListView1.Items[ii].Caption+' 更名为 '+
getmaskstring(tmpstr,'^',2));
ListView1.Items[ii].Caption:=getmaskstring(tmpstr,'^',2);
for jj:=0 to ListView1.Items.Count -1 do begin
user:=ListView1.Items[ii].Caption+'^'+ListView1.Items[ii].subitems[0]+'^'+

ListView1.Items[ii].SubItems[1]+'^'+ListView1.Items[ii].subitems[2];
ServerSocket1.Socket.Connections[jj].SendText('昵称@#!^'+User+'^');
end;
end;
end;
end;
end;
end;

客户端:

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
tmpstr:string;
newItem:TListItem;
ii:Integer;
exist:bool;
commHead:string;
begin
exist:=false;
tmpstr:=Socket.ReceiveText;
commHead:=getmaskstring(tmpstr,'^',1);
//Richedit1.Lines.Add(tmpstr);
if commHead ='昵称@#!'then
begin
for ii:=0 to ListView1.Items.Count -1 do
begin
if getmaskstring(tmpstr,'^',5)=ListView1.Items[ii].SubItems[2]
then
begin
exist:=true;
if getmaskstring(tmpstr,'^',2)<>ListView1.Items[ii].Caption then
begin
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
ListView1.Items[ii].Caption+' 更名为 '+
getmaskstring(tmpstr,'^',2));
ListView1.Items[ii].Caption:=getmaskstring(tmpstr,'^',2);

end;
end;
end;
end;
if commHead='交谈@#!'then
begin
Richedit1.Lines.Add(getmaskstring(tmpstr,'^',2));
end;
if commHead='增加用户@#!'then
begin
for ii:=0 to ListView1.Items.Count-1 do
begin
if getmaskstring(tmpstr,'^',5)=ListView1.Items[ii].SubItems[2] then
exist:=true;
end;
if exist=false then begin
newitem:=ListView1.Items.add();
newitem.Caption:=getmaskstring(tmpstr,'^',2);
newitem.SubItems.Add(getmaskstring(tmpstr,'^',3));
newitem.SubItems.Add(getmaskstring(tmpstr,'^',4));
newitem.SubItems.Add(getmaskstring(tmpstr,'^',5));
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
getmaskstring(tmpstr,'^',2)+'加入进来!');

end;
end;
if commHead='删除用户@#!'then
begin
for ii:=0 to ListView1.Items.Count-1 do
begin
if getmaskstring(tmpstr,'^',5)=ListView1.Items[ii].SubItems[2] then
begin
Listview1.Items.Delete(ii);
Richedit1.Lines.Add(DateToStr(Date)+' '+TimeToStr(time)+'==>>'+
getmaskstring(tmpstr,'^',2)+'走了!');

end;
end;
end;
end;

搜索更多相关主题的帖子: 注释 代码 
2007-06-01 00:12
快速回复:求助:代码注释
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019039 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved