Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
Delphi 7 Enterprise
|
Re: TThread Execute Methode dauerhaft laufen lassen
17. Mai 2008, 20:32
Delphi-Quellcode:
type
TSockThread = class(TThread)
iSock: Cardinal;
recvProc: procedure(szString: String);
procedure Execute; override;
protected
FBuffer:string;
procedure CallRecvProc;
end;
TSmallSock = class
constructor Create(Address: PChar; Port: Cardinal);
procedure Free;
private
lpAddress: PChar;
dwPort: Cardinal;
iSock: Cardinal;
WSAData: TWSAData;
addrIn: TSockAddrIn;
dwThreadID: Cardinal;
gThread: TSockThread;
public
procRecv: procedure(szString: String);
function DoConnect:Boolean;
function SendString(szString: String):Boolean;
end;
var gSmallSock: TSmallSock;
implementation
procedure TSockThread.CallRecvProc;
begin
recvProc(FBuffer);
end;
procedure TSockThread.Execute;
var
mBuf: array[0..1000-1] of Char;
begin
if recv(iSock, mBuf, sizeof(mBuf), 0) <> SOCKET_ERROR then
begin
if mBuf <> '' then
begin
FBuffer:=mBuf;
synchronize(CallRecvProc);
mBuf := '';
end;
end;
end;
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
|