I want to write a simple proxy with TIdHTTPProxyServer
and this is my code :
void __fastcall TForm1::FormCreate(TObject *Sender)
{
IdHTTPProxyServer1->DefaultPort = 8090;
IdHTTPProxyServer1->Active = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
int Index = 0;
TList * cList;
{
cList = IdHTTPProxyServer1->Contexts->LockList();
try
{
for ( int stop = cList->Count - 1, Index = 0; Index <= stop; Index++)
{
TIdContext * t;
t = static_cast <TIdContext*>(cList[Index]);
t->Connection->Disconnect();
}
}
__finally
{
IdHTTPProxyServer1->Contexts->UnlockList();
}
IdHTTPProxyServer1->Active = false;
}
}
I have two Question :
How can I cast a TList to a TIdContext?
This code doesn't change my IP and I want to change my IP. How can I change my IP with
TIdHTTPProxyServer
?
You don't, as they are not related classes. The real problem is that you are not accessing the
TList
items correctly to begin with. You need to use theTList::Items[]
property instead, either directly:Or indirectly, by dereferencing the
TList
pointer so thatTList::operator[]
(which uses theItems[]
property internally) can be invoked:Either way, this code is completely unnecessary, as Indy will automatically close all active clients for you when the server is deactivated/destroyed:
You cannot change the local machine's IP with
TIdHTTPProxyServer
, that is not it is meant for. In fact, there is nothing in Indy to change the local machine's IP, that is outside of Indy's scope. You have to use platform-specific APIs for that instead. What are you trying to accomplish exactly? Please post a separate question about this topic, and explain your requirements for it.