Haruyuki Mohri


How to use "async" and "future<>" in XE8(Win64)

Use the "async", how to get the http data asynchronously.

"C++Builder XE8" is only in Win64, are supported C++11.
So, "future<>" it can also be used.

void __fastcall TForm1::Button1Click(TObject *Sender)
    String url = L"http://www.mojeld.com/";
    std::future<String> fs;
    fs = std::async(std::launch::async, [url]()->String {
        std::shared_ptr<TStringStream> ss(new TStringStream(url,TEncoding::UTF8, false));
        std::shared_ptr<TIdHTTP> http(new TIdHTTP(NULL));
        http->Get(url, ss.get());
        String stGet = ss->DataString;
        return stGet;
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
    Memo1->Lines->Append( fs.get() );

I used a lambda.
But, the method that does not use a lambda is also possible.

C++Builder(Win32) also hope the C++11 support.