Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Access violation inside TIdTCPClientCustom
| Subject: | Re: Access violation inside TIdTCPClientCustom |
| Posted by: | "Michael Stieler" (michael.stiel..@rie.eu) |
| Date: | Tue, 22 Jan 2008 12:55:27 |
Remy Lebeau (TeamB) schrieb:
> "Michael Stieler" <michael.stieler@rie.eu> wrote in message
> news:478f3892@newsgroups.borland.com...
>
>> As for the build number, I dont't know where to look for this.
>
> Right-click on any Indy component in the form designer.
>
Okay , we are using Version 10.1.6.
>
>> The problem is, that IOHandler is nil at this point
>
> Well, that would certainly explain the AV, but the real problem is that it
> shouldn't be nil at that point. You already showed why - TIdTCPClient
> created an IOHandler object internally if one doesn't already exist. So
> this goes back to my earlier idea that you are not using the TIdTCPClient
> correctly in your own threading code. You are probably doing something in
> your worker thread that indirectly destroys the IOHandler while Connect() is
> still trying to initialize it.
Yes, that's what I think. I'll have a look at how this could happen..
>
>> This is what I was thinking about. Connect() blocks until success
>> or failure, so my poll thread couldn't call during this time.
>
> Why is your polling thread even running at all while the client is still
> trying to connect to the server? There is nothing to poll yet. Why are you
> trying to poll and connect at the same time? Don't do that. Connect fully
> first, then start polling if the connection succeeded.
The poll thread is running because it handles multiple connections.
The way it works shouldn't do anything during a Connect() command.
A simplified example of what the poll thread does:
for I := 0 to Length(conns) - 1 do
begin
try
if not conns[I].IsConnected then conns[I].Connect;
except
end;
if conns[I].IsConnectedAndLoggedIn then
begin
conns[I].SendCommandLn(command);
conns[I].ReadCommandResponseLn;
end;
end;
for i := 1 to 4 do
begin
If terminated then exit;
Sleep(500);
end;
and the TConnection.Connect function does
if conn.Connected then raise Exception.Create(..);
try
conn.Connect;
except
conn.Disconnect;
raise;
end;
if the connection was established the following event handler:
procedure TConnection.Connected(ASender : TObject);
begin
try
SendLoginSequence;
FLoggedIn := true;
except
Disconnect;
end;
end;
Thanks for spending your time,
Michael