Type
Label1: TLabel; //这里已经定义了Label1
TServerThread = class(TThread)
private
ADOConnection: TADOConnection; protected
procedure Execute; override;
public
Buffer:Array [1..2048] of Char;
ServerUDP:TIdUDPServer;
PeerInf:TPeerInfo;
procedure ConnectDB();
destructor Destroy;override;
end;
===============================================================
procedure TMainForm.ServerUDPUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
buffer:Array[1..2048] of char;
ServerThread:TServerThread;
PeerInf:TPeerInfo;
begin
try
AData.ReadBuffer(buffer,Sizeof(AData));
ServerThread:=TServerThread.Create(True); //实例化一个服务线程
ServerThread.ServerUDP:=ServerUDP;
PeerInf.PeerIP:=ABinding.PeerIP;
PeerInf.PeerPort:=ABinding.PeerPort;
ServerThread.PeerInf:=PeerInf;
CopyMemory(@(ServerThread.Buffer),@Buffer,AData.Size);
ServerThread.Resume;
except
end;
end;
===================================================================
procedure TServerThread.Execute;
var
ceType:char;
CBLogin:TCBLogin; //数据结构
CBLoginResult:TCBLoginResult; //数据结构
CBGetMyIPAndPort:TCBGetMyIPAndPort; //数据结构
CBPleaseCallMe:TCBPleaseCallMe; //数据结构
CBCalled:TCBCalled; //数据结构
CBP2PResponse:TCBP2PResponse; //数据结构
begin
try
ceType:=Buffer[1]; if ceType = ceLogin then
begin
CopyMemory(@CBLogin,@Buffer[2],SizeOf(CBLogin));
Label1.Caption:=CBLogin.LoginName; //这句提示我没有定义Label1
// MessageBox(Handle,CBLogin.Password,'提示',MB_ICONINFORMATION);
end;
=========================================================================
说明:以上代码是我从一个delphi 关于通信编程方面的demo中copy下来,学习的过程中遇到的.
问题: 1 TServerThread.Execute 的调用是在 ServerThread:=TServerThread.Create(True); {实例化一个服务线程 } 中实现的吗?
2 为什么在 TServerThread.Execute中不能调用 窗体控件
3 如果我要根据ceType 的传入值,进行具体的操作.比如查询数据库,返回用户具体信息.我又该如何在这个execute中来进行.关键是她现在访问不了在TServerThread.Execute外定义的一些控件
4 在Label1.Caption:=CBLogin.LoginName; 这句中,我用CBLogin.LoginName能不能接收到登陆的用户名,书写是否正确?
============================================================================
ps: 先谢谢路过的朋友
我的联系方式: QQ 24578574
Msn: [email protected]
请朋友帮帮忙,给指点一下.
Label1: TLabel; //这里已经定义了Label1
TServerThread = class(TThread)
private
ADOConnection: TADOConnection; protected
procedure Execute; override;
public
Buffer:Array [1..2048] of Char;
ServerUDP:TIdUDPServer;
PeerInf:TPeerInfo;
procedure ConnectDB();
destructor Destroy;override;
end;
===============================================================
procedure TMainForm.ServerUDPUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
buffer:Array[1..2048] of char;
ServerThread:TServerThread;
PeerInf:TPeerInfo;
begin
try
AData.ReadBuffer(buffer,Sizeof(AData));
ServerThread:=TServerThread.Create(True); //实例化一个服务线程
ServerThread.ServerUDP:=ServerUDP;
PeerInf.PeerIP:=ABinding.PeerIP;
PeerInf.PeerPort:=ABinding.PeerPort;
ServerThread.PeerInf:=PeerInf;
CopyMemory(@(ServerThread.Buffer),@Buffer,AData.Size);
ServerThread.Resume;
except
end;
end;
===================================================================
procedure TServerThread.Execute;
var
ceType:char;
CBLogin:TCBLogin; //数据结构
CBLoginResult:TCBLoginResult; //数据结构
CBGetMyIPAndPort:TCBGetMyIPAndPort; //数据结构
CBPleaseCallMe:TCBPleaseCallMe; //数据结构
CBCalled:TCBCalled; //数据结构
CBP2PResponse:TCBP2PResponse; //数据结构
begin
try
ceType:=Buffer[1]; if ceType = ceLogin then
begin
CopyMemory(@CBLogin,@Buffer[2],SizeOf(CBLogin));
Label1.Caption:=CBLogin.LoginName; //这句提示我没有定义Label1
// MessageBox(Handle,CBLogin.Password,'提示',MB_ICONINFORMATION);
end;
=========================================================================
说明:以上代码是我从一个delphi 关于通信编程方面的demo中copy下来,学习的过程中遇到的.
问题: 1 TServerThread.Execute 的调用是在 ServerThread:=TServerThread.Create(True); {实例化一个服务线程 } 中实现的吗?
2 为什么在 TServerThread.Execute中不能调用 窗体控件
3 如果我要根据ceType 的传入值,进行具体的操作.比如查询数据库,返回用户具体信息.我又该如何在这个execute中来进行.关键是她现在访问不了在TServerThread.Execute外定义的一些控件
4 在Label1.Caption:=CBLogin.LoginName; 这句中,我用CBLogin.LoginName能不能接收到登陆的用户名,书写是否正确?
============================================================================
ps: 先谢谢路过的朋友
我的联系方式: QQ 24578574
Msn: [email protected]
请朋友帮帮忙,给指点一下.
解决方案 »
- 100年前我就可以75你...你想怎么样??
- 谁有ModelMaker for D6的正式版
- 如何掩藏应用程序(用ctrl+alt+del看不到),并且可以随系统一起启动
- 关于select * from Rcdjb order by convert(int,id) desc
- DesignReport这个控件大家有没有用过,我想找一个支持ADO的版本,不知谁有???高分感谢
- 给几个字符串函数
- 怎么让FORM响应键盘事件?
- “爽”
- 关于ADO几个控件的速度问题
- 各位:周末愉快!为何我的多表查询用updatebatch提交时总是报错?
- ADOQuery执行查询时出现Cannot perform this operation on a closed dataset
- 能不能将.EXE与数据库邦再一起 就一个文件?
如果是不是看到jeffamy(风中聆听)我还不知道你哪个群的