Lena wrote:Please tell me how to fix this?
THTTPClient *aHTTP = new THTTPClient;
[bccaarm Error] UnitINI.cpp(30): allocating an object of abstract class type 'System::Net::Httpclient::THTTPClient'
That means THTTPClient has an abstract method in it (the compiler should be telling you exactly which one) and thus cannot be instantiated directly, you must use a derived class instead.
I didn't realize that THTTPClient.Create() is just a class method and not an actual constructor (most constructors in Delphi are named Create). So the C++ way to instantiate THTTPClient is:
- Code: Select all
THTTPClient *aHTTP = THTTPClient::Create();
Otherwise, use TNetHTTPClient instead:
- Code: Select all
TNetHTTPClient *aHTTP = new TNetHTTPClient(nullptr);
Lena wrote:Can I use this code to check connection with TidHTTP in Internet projects iOS and Android?
Technically yes, but again, use brackets only on an IPv6 enabled network. You still need to support IPv4 networks as well. Also, there is no point in using Get() if you are going to ignore the data received. Use Head() instead.
You could try something more like this:
- Code: Select all
void __fastcall TForm1::Image1Click(TObject *Sender)
{
try
{
IdHTTP1->Head("http://[google.com]/");
}
catch(const System::Sysutils::Exception &)
{
try
{
IdHTTP1->Head("http://google.com/");
}
catch(const System::Sysutils::Exception &)
{
ShowMessage(L"No Internet connection.");
return;
}
}
FormWEB = new TFormWEB(this);
FormWEB->WebBrowser1->Navigate(L"http://bcbj.org/forums");
FormWEB->Show();
}
But really, it is redundant to check the connection manually since the web browser is going to do that anyway, so just let the browser handle it. It should report any errors to you. Also, it is very important that you NOT perform blocking operations (like TIdHTTP) on the main UI thread at all on iOS and Android. They must be in a worker thread instead.