Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Dec : AContext.Data problem
| Subject: | AContext.Data problem |
| Posted by: | "Gary Hopwood" (h..@fwsite.com) |
| Date: | Sun, 11 Dec 2005 19:57:43 |
I am having problems with keeping information in AContext.Data area. This
being my first attempt using Indy 10. Delphi 2005 upd3.
I get an Access violation exception at address xxxxxxx in module XXXX.exe.
Write of address 00000001. Whenever I try to update the context data within
the .Execute It reads the data that was set in the connection event from
AContext.Data with no problem.
Application requires a couple of message sequences/validations etc. before
normal processing is allowed.
Any illumination will be greatly appreciated.
Here is revelant code:
Type TConnInfo = class(TObject)
public
RmtName : string;
State1 : boolean;
State2 : boolean;
end;
procedure TForm1.TCPSConnect(AContext: TIdContext);
begin
AContext.Data := TConnInfo.Create;
TConnInfo(AContext.Data).State1 := false;
TConnInfo(AContext.Data).State2 := false;
end;
procedure TForm1.TCPSDisconnect(AContext: TIdContext);
begin
AContext.Data.Free;
Acontext.Data := nil;
end;
procedure TForm1.TCPSExecute(AContext: TIdContext);
var
msgin : Tbytes;
alliswell : boolean;
Remaining : integer;
begin
with AContext.Connection.IOHandler do
begin
if not TConnInfo(AContext.Data).State1 then
begin
// get the first msg in connection validation sequence
readbytes(MsgIn, 32); // read in Msg//
// do some stuf
if alliswell then
// ********* NEXT INSTRUCTION THROWS THE EXCEPTION ***************
TConnInfo(AContext.Data).State1 := true // update state of connection
else
AContext.Connection.Disconnect;
end
else if not TConnInfo(AContext.Data).State2 then
begin
// get second msg in the connection validation sequence
readbytes(MsgIn, 32); // read in Msg header//
// calc balance of message left to be read
remaining := TotalMsg - 32;
readbytes(MsgIN, remaining);
// check their info
.// prepare our return msg for state 2 of connection
// send it
if alliswell then
TConnInfo(AContext.Data).State2 := true // update state of connectio
else
AContext.Connection.Disconnect;
end
else // All validations passed normal message processing
begin
readbytes(MsgIn, 32); // read in Msg //
// calc balance of message left to be read
remaining := TotalMsg - 32;
readbytes(MsgIN, remaining);
// do a bunch of stuff to handle msg
// ack them
end;
end; // with
end; // execute proc