Implement CreateAnonymousThread with BCC32.

by Sep 13, 2017

C++Builder 10.2 BCC32 can not write lambda. 
So write an implementation in Invoke() with TCppInterfacedObject<>.

struct T_thread_proc :  TCppInterfacedObject<TProc>{
    TNotifyEvent f_ev_;
    struct T_sync_proc :  TCppInterfacedObject<TThreadProcedure>{
        TNotifyEvent f_ev_;
        T_sync_proc(TNotifyEvent& ev2){ f_ev_ = ev2; }
        virtual void __fastcall Invoke() {
            //Inside Synchronize.
            f_ev_(NULL//Execute "TNotifyEvent".
    T_thread_proc(TNotifyEvent ev1){f_ev_ = ev1; }
    virtual void __fastcall Invoke() {
        //Write thread execution code here.
        //Finally call Synchronize.
            TThread::CurrentThread,_di_TThreadProcedure(new T_sync_proc(f_ev_)));

Event prepared for calling with TThread::Synchronize().

void __fastcall TForm1::do_thread_event(TObject *Sender)
    Button1->Enabled    = truefalsefalse"End CreateAnonymousThread"

Call TThread::CreateAnonymousThread() with a TButton event.

Place the TButton and TActivityIndicator

void __fastcall TForm1::Button1Click(TObject *Sender)
    TThread::CreateAnonymousThread(_di_TProc( new T_thread_proc(&do_thread_event)))->Start();
    Caption = "Started CreateAnonymousThread"truetruefalse

Build execution.

When you click the Button1, until the thread is finished "ActivityIndicator1->Animate = true";