title: Delphi: Unique variable for each TIdcontext
body: <p>I am having issue with declaring a unique global variable for each connection of IdTCPServer. What i am trying to do here is.</p>
  
  <pre><code>TMyContext = class(TIdServerContext)
    public
      Tag: Integer;
      Queue: TIdThreadSafeList;
      FPacketBuffer: Pointer;
      PacketBufferPtr: Integer;
  
      constructor Create(AConnection: TIdTCPConnection; AYarn: TIdYarn; AList: TThreadList = nil); override;
      destructor Destroy; override;
    end;
  </code></pre>
  
  <p>and then accessing the variable using TMyContext(AContext).FPacketBuffer, but i get an access violation error when there is a connection active and a new connection tries to connect. here is what is in my idTcpConnect and idTcpDisconnect</p>
  
  <pre><code>procedure TMainFrm.MainSckConnect(AContext: TIdContext);
  begin
    TMyContext(AContext).Queue.Clear;
    TMyContext(AContext).Tag := -1;
    GetMem(TMyContext(AContext).FPacketBuffer,65536);
  end;
  
  procedure TMainFrm.MainSckDisconnect(AContext: TIdContext);
  Var Client: TClientInfo;
  begin
  //If TMyContext(AContext).Queue.Count &gt; 0 Then TMyContext(AContext).Queue.Clear;
  TMyContext(AContext).Queue.Clear;
  FreeMem(TMyContext(AContext).FPacketBuffer);
  If AContext.Data &lt;&gt; nil Then Begin
    Client := Pointer(AContext.Data);
    Clients.Remove(Client);
    Client.Free;
    AContext.Data := nil;
  End;
  end;
  </code></pre>
  
  <p>The error occures when getmem is called in idtcpconnect, i think i am doing it all wrong, i am not sure how i can have a unique global variable for each context.</p>