R
rackrain
Unregistered / Unconfirmed
GUEST, unregistred user!
采用一个serversocket控件的type为stThreadBlocking,现在从客户端传来数据,采用线程来从后台的数据库中取出数sendstr(string类型),在发送后报错,请问是什么原因??
主程序如下:
procedure TForm1.ServerSocketGetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
var mm:dataread;
begin
mm:=dataread.Create(ClientSocket);
end;
线程如下:
unit datareadthread;
interface
uses
Classes,ADODB,ComObj,Activex,idGlobal,SysUtils,Messages,windows,StdCtrls,ScktComp;
type
dataread = class(TThread)
private
{ Private declarations }
client_bank:TServerClientWinSocket;
sendstr:string;
clientsend:String;
FADOConnection:TADOConnection;
FADOQuery:TADOQuery;
protected
procedure QuerySend;
procedure WriteSend;
// procedure CancelSend;
procedure Execute; override;
public
constructor Create(const client:TServerClientWinSocket);
end;
implementation
uses dxsend;
{ dataread }
constructor dataread.Create(const client:TServerClientWinSocket);
begin
FreeOnTerminate:= True;
client_bank:=client;//
inherited Create(False);
end;
procedure dataread.Execute;
var Stream : TWinSocketStream;
buffer1: array[0 .. 69] of Char;
begin
Stream := TWinSocketStream.Create(client_bank, 3000);
FillChar(Buffer1,76, 0);
if Stream.WaitForData(2000) then //等待数据到来
begin
if Stream.Read(Buffer1,83) = 0 then //读数据
client_bank.Close
else
begin
//处理受到的数据
clientsend:=buffer1;
form1.SnEdit1.Text:=clientsend;
case strtoint(copy(clientsend,3,3)) of
110:QuerySend;//对后台的数据库进行操作
120:WriteSend;对后台的数据库进行操作
end;
client_bank.SendText(sendstr);//sendstr是要传给客户端的字符串
Stream.Free;
client_bank.Close;
end;
end
else
client_bank.Close;
end;//执行完后抱错,抱错如下:'external exception c000001D'
另外,采用阻塞方式时速度明显变慢,请问是什么原因??
主程序如下:
procedure TForm1.ServerSocketGetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
var mm:dataread;
begin
mm:=dataread.Create(ClientSocket);
end;
线程如下:
unit datareadthread;
interface
uses
Classes,ADODB,ComObj,Activex,idGlobal,SysUtils,Messages,windows,StdCtrls,ScktComp;
type
dataread = class(TThread)
private
{ Private declarations }
client_bank:TServerClientWinSocket;
sendstr:string;
clientsend:String;
FADOConnection:TADOConnection;
FADOQuery:TADOQuery;
protected
procedure QuerySend;
procedure WriteSend;
// procedure CancelSend;
procedure Execute; override;
public
constructor Create(const client:TServerClientWinSocket);
end;
implementation
uses dxsend;
{ dataread }
constructor dataread.Create(const client:TServerClientWinSocket);
begin
FreeOnTerminate:= True;
client_bank:=client;//
inherited Create(False);
end;
procedure dataread.Execute;
var Stream : TWinSocketStream;
buffer1: array[0 .. 69] of Char;
begin
Stream := TWinSocketStream.Create(client_bank, 3000);
FillChar(Buffer1,76, 0);
if Stream.WaitForData(2000) then //等待数据到来
begin
if Stream.Read(Buffer1,83) = 0 then //读数据
client_bank.Close
else
begin
//处理受到的数据
clientsend:=buffer1;
form1.SnEdit1.Text:=clientsend;
case strtoint(copy(clientsend,3,3)) of
110:QuerySend;//对后台的数据库进行操作
120:WriteSend;对后台的数据库进行操作
end;
client_bank.SendText(sendstr);//sendstr是要传给客户端的字符串
Stream.Free;
client_bank.Close;
end;
end
else
client_bank.Close;
end;//执行完后抱错,抱错如下:'external exception c000001D'
另外,采用阻塞方式时速度明显变慢,请问是什么原因??