Board index » delphi » Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)

Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)

Hi.

I just upgraded to Indy v8.1
Everything works fine except when my application closes. I get a access
violation error. The Delphi IDE then points me to this line of code in
TIdTCPConnection.ReadFromStack.
--> = line IDE points at.

procedure DefaultRecv(ADestStream: TIdBuffer; var VByteCount: integer);
  begin
    // No need to call AntiFreeze, the Readable does that.
-->  VByteCount := IOHandler.Recv(ADestStream.Memory^, ADestStream.Size);
  end;

Why does this happen in v8.1 and not 8.0 ?

Any help would be great thanks!:))
Regards
Steve

 

Re:Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)


Quote
"Steve" <s...@icon.co.za> wrote in message news:3b3fda5c_1@dnews...

Hi,

Quote
> procedure DefaultRecv(ADestStream: TIdBuffer; var VByteCount: integer);
>   begin
>     // No need to call AntiFreeze, the Readable does that.
> -->  VByteCount := IOHandler.Recv(ADestStream.Memory^, ADestStream.Size);
>   end;

> Why does this happen in v8.1 and not 8.0 ?

I don't know this, but what i would do is make some tests to see if the
buffer is assigned before actually using it, so rewriting the proc as
follows:

Quote
> procedure DefaultRecv(ADestStream: TIdBuffer; var VByteCount: integer);
>   begin
>     // No need to call AntiFreeze, the Readable does that.

       // check if the buffer exists
      if assigned(ADestStream) then
        VByteCount := IOHandler.Recv(ADestStream.Memory^, ADestStream.Size)
     else
        vByteCount := 0; { or -1 to indicate that your buffer wasn't
assigned or something..}

Quote
>   end;

This will prevent many a problem when somehow this procedure gets called
somewhere halfway the destruction parts on termination of your application.

Re:Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)


Quote
"Arthuro" <hexorha...@vaxor.com> wrote in message news:3b402757_2@dnews...
> "Steve" <s...@icon.co.za> wrote in message news:3b3fda5c_1@dnews...
> This will prevent many a problem when somehow this procedure gets called
> somewhere halfway the destruction parts on termination of your

application.

Hi Arhuro

I tried a if assigned...etc and I still get a access violation ? So I cant
see what VByteCount returns.
Do you think its a Indy 8.1 problem or a problem with my application ? Im
assuming the problem is with 8.1 because my code has been working with 'all'
the previous versions of Indy....unless theres a problem with my code and
now only Indy 8.1 is showing it ?

Re:Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)


The problem is in unassinged IOHanlder. Update your copy of Indy 8.1 from
the FTP server.
I think this is something specific to your program.

Doychin

--
eng. Doychin Bondzhev
doyc...@dsoft-bg.com
DdSoft-Bulgaria
http://www.dsoft-bg.com

Quote
"Arthuro" <hexorha...@vaxor.com> wrote in message news:3b402757_2@dnews...
> "Steve" <s...@icon.co.za> wrote in message news:3b3fda5c_1@dnews...

> Hi,

> > procedure DefaultRecv(ADestStream: TIdBuffer; var VByteCount: integer);
> >   begin
> >     // No need to call AntiFreeze, the Readable does that.
> > -->  VByteCount := IOHandler.Recv(ADestStream.Memory^,
ADestStream.Size);
> >   end;

> > Why does this happen in v8.1 and not 8.0 ?

> I don't know this, but what i would do is make some tests to see if the
> buffer is assigned before actually using it, so rewriting the proc as
> follows:

> > procedure DefaultRecv(ADestStream: TIdBuffer; var VByteCount: integer);
> >   begin
> >     // No need to call AntiFreeze, the Readable does that.

>        // check if the buffer exists
>       if assigned(ADestStream) then
>         VByteCount := IOHandler.Recv(ADestStream.Memory^,
ADestStream.Size)
>      else
>         vByteCount := 0; { or -1 to indicate that your buffer wasn't
> assigned or something..}
> >   end;

> This will prevent many a problem when somehow this procedure gets called
> somewhere halfway the destruction parts on termination of your
application.

Re:Access Violation error with Indy v8.1 (TIdTCPConnection.ReadFromStack)


Quote
"Steve" <s...@icon.co.za> wrote in message news:3b40a0c7_2@dnews...

> "Arthuro" <hexorha...@vaxor.com> wrote in message news:3b402757_2@dnews...
> > "Steve" <s...@icon.co.za> wrote in message news:3b3fda5c_1@dnews...
> > This will prevent many a problem when somehow this procedure gets called
> > somewhere halfway the destruction parts on termination of your
> application.

> Hi Arhuro

> I tried a if assigned...etc and I still get a access violation ? So I cant
> see what VByteCount returns.
> Do you think its a Indy 8.1 problem or a problem with my application ? Im
> assuming the problem is with 8.1 because my code has been working with
'all'
> the previous versions of Indy....unless theres a problem with my code and
> now only Indy 8.1 is showing it ?

Hi Steve,

As Doychin says, it's probably an unassigned IOHandler.

I think it's best to test everything that has to be created/assigned with an
'if assigned() then' construction if you have no control over the assignment
of these parts.
And even if you do have control over it, can you be certain that no-one will
call that function if something has not been assigned? In all my programs i
use this construction. I think it's always better to catch the exception
before it can happen, rather than to catch it with a try except block.

In many cases i've seen Try Except blocks are used to cover up bad
programming..

Greetz,
Marco..

Other Threads