最初の質問:
次のルーチンは、Indy 9 IdTcpServer.OnExecute ルーチンの正しい実装ですか?
procedure TMyConnServer.ServerExecute(AContext: TIdPeerThread);
var
buffSize: integer;
str: string;
begin
AContext.Connection.ReadFromStack(True, 600, False);
buffSize := AContext.Connection.InputBuffer.Size;
if (buffSize > 0) then
{ Extract input buffer as string }
str := AContext.Connection.ReadString(buffSize);
{ Notify connection object of received data }
if (AContext.Data <> nil) then
begin
TConnectionHandler(AContext.Data).Read(str);
end;
end;
end;
2番目の(実際にはもっと重要な)質問:
現在、アクセス違反 (アドレス 000000 からの読み取り) が時々発生しています。明らかに行で:
AContext.Connection.ReadFromStack(True, 600, False);
ただし、AContext / Connection / InputBuffer / IOHandler = nil BEFORE が false かどうかを確認します。呼び出しの後 (および例外が発生した後)、IOHandler は nil です。
RAD Studio / Delphi 2007 を使用しています。