W
wisenow
Unregistered / Unconfirmed
GUEST, unregistred user!
1.
// 要在线程里响应消息
// 出现无效句柄错误
unit Unit2;
interface
uses
Classes, Windows, Messages;
type
TMyThread = class(TThread)
FHandle1: THandle;
procedure WinProc(var Msg: TMessage);
function GetHandle: THandle;
protected
procedure Execute; override;
public
constructor Create;
destructor Destroy;
property Handle1: THandle read GetHandle;
end;
implementation
{ TMyThread }
constructor TMyThread.Create;
begin
if Handle1 = 0 then
Exit;
end;
destructor TMyThread.Destroy;
begin
if FHandle1 <> 0 then
DeallocateHWnd(FHandle1);
end;
procedure TMyThread.Execute;
begin
inherited;
end;
function TMyThread.GetHandle: THandle;
begin
if FHandle1 = 0 then
FHandle1 := AllocateHwnd(WinProc);
Result := FHandle1;
end;
procedure TMyThread.WinProc(var Msg: TMessage);
begin
try
Dispatch(Msg);
except
if Assigned(ApplicationHandleException) then
ApplicationHandleException(Self);
end;
end;
end.
2. 用TClientSocket和TServerSocket通信时,怎样才能释放SendStream发出去的Stream
在没有Disconnect的情况下,因为我还要接着发送很多内容。
3. 用底层的Socket编程时,当调用WSAAsyncSelect(FSock, Handle, WM_SOCKETMSG, FD_READ);
时为什么我的程序收不到消息, 而另一方发送确实已经执行了, 这些代码有问题吗?
发送代码
A := 'ABCDEFGHIJ';
GetMem(Buf, 10);
FillChar(Buf, 10, A[0]);
SendPacket(Buf, Msg.Socket);
//FreeMem(Buf);
ShowMessage('Send OK');
//-----以下为SendPacket过程-----------
procedure SendPacket(var Buf; Sock: TSocket);
var
R: Longint;
begin
R := Send(Sock, Buf, SizeOf(Buf), 0);
if R = SOCKET_ERROR then
ShowMessage('Send() Error!');
end;
如果谁有热心帮我解决此问题,我发代码过去。感激不尽。
--------------------------------------------------------
这是我到这里的第一贴,还望各位捧场。
// 要在线程里响应消息
// 出现无效句柄错误
unit Unit2;
interface
uses
Classes, Windows, Messages;
type
TMyThread = class(TThread)
FHandle1: THandle;
procedure WinProc(var Msg: TMessage);
function GetHandle: THandle;
protected
procedure Execute; override;
public
constructor Create;
destructor Destroy;
property Handle1: THandle read GetHandle;
end;
implementation
{ TMyThread }
constructor TMyThread.Create;
begin
if Handle1 = 0 then
Exit;
end;
destructor TMyThread.Destroy;
begin
if FHandle1 <> 0 then
DeallocateHWnd(FHandle1);
end;
procedure TMyThread.Execute;
begin
inherited;
end;
function TMyThread.GetHandle: THandle;
begin
if FHandle1 = 0 then
FHandle1 := AllocateHwnd(WinProc);
Result := FHandle1;
end;
procedure TMyThread.WinProc(var Msg: TMessage);
begin
try
Dispatch(Msg);
except
if Assigned(ApplicationHandleException) then
ApplicationHandleException(Self);
end;
end;
end.
2. 用TClientSocket和TServerSocket通信时,怎样才能释放SendStream发出去的Stream
在没有Disconnect的情况下,因为我还要接着发送很多内容。
3. 用底层的Socket编程时,当调用WSAAsyncSelect(FSock, Handle, WM_SOCKETMSG, FD_READ);
时为什么我的程序收不到消息, 而另一方发送确实已经执行了, 这些代码有问题吗?
发送代码
A := 'ABCDEFGHIJ';
GetMem(Buf, 10);
FillChar(Buf, 10, A[0]);
SendPacket(Buf, Msg.Socket);
//FreeMem(Buf);
ShowMessage('Send OK');
//-----以下为SendPacket过程-----------
procedure SendPacket(var Buf; Sock: TSocket);
var
R: Longint;
begin
R := Send(Sock, Buf, SizeOf(Buf), 0);
if R = SOCKET_ERROR then
ShowMessage('Send() Error!');
end;
如果谁有热心帮我解决此问题,我发代码过去。感激不尽。
--------------------------------------------------------
这是我到这里的第一贴,还望各位捧场。