简体   繁体   English

C++ Builder 11.1.5 - 线程 Class - 所有成员现在都是私有的,不能在线程外访问

[英]C++ Builder 11.1.5 - Thread Class - All members are now private and not accessible outside of the thread

Looking at RAD Studio 11.1.5 and wrote a small C++ Builder test program using a thread.看着 RAD Studio 11.1.5 写了一个小的 C++ Builder 测试程序使用线程。 I keep getting compiler errors as follows:我不断收到如下编译器错误:

// Execute routine of the TestThread

void __fastcall TTestThread::Execute()
{
int i,j,k;
bool MatrixOk;
long double Answer, ReadValue, SubDeterminant;

const HRESULT iniResult = CoInitializeEx(0, COINIT_MULTITHREADED);

if (!((iniResult == S_OK) || (iniResult == S_FALSE))) {
    Application->MessageBox(L"Failed to initialize COM library.\n",L"Thread Error", MB_OK);
    return;
    }

// Place main part of thread here

while(!Terminated) {
    Synchronize(UpdateDisplay);
    Sleep(1000);
    }

TheMessage = "Terminating...  Cya";
Synchronize(ShowMessage);
CoUninitialize();

return;
}

void __fastcall TTestThread::UpdateDisplay()
{
Counter++;
MainForm->SB->SimpleText = "Counter: "+IntToStr(Counter);
MainForm->SB->Repaint();

return;

}


void __fastcall TMainModelThread::ShowMessage()
{
Application->MessageBox(TheMessage.w_str(),L"A Message", MB_OK);
return;

}

// Code that generates the errors below called from the main form OnClose event

MainModelThread->Terminate();

Compiler error messages as follows:编译错误信息如下:

[bcc64 Error] MainFrm.cpp(90): 'Terminate' is a private member of 'System::Classes::TThread'
  MainFrm.h(17): constrained by implicitly private inheritance here
  System.Classes.hpp(2726): member is declared here
[bcc64 Error] MainFrm.cpp(90): cannot cast 'TTestThread' to its private base class 'System::Classes::TThread'
  MainFrm.h(17): implicitly declared private here

Is anyone else noticing this?有其他人注意到这一点吗? This code would compile under C++ Builder 10.3.1.此代码将在 C++ Builder 10.3.1 下编译。

You did not show the declaration of the TTestThread class, but the error messages are clearly saying that you are inheriting from TThread using (implicitly) private inheritance , making all members of TThread private and thus inaccessible to your class.您没有显示TTestThread class 的声明,但错误消息清楚地表明您正在使用(隐式) 私有inheritanceTThread继承,使TThread的所有成员都是私有的,因此您的 ZA2F2ED4F8EBC2ABCBBB4Z2C 无法访问。 You must use public inheritance instead, eg:您必须改用public inheritance ,例如:

class TTestThread : public TThread
                    ^^^^^^

Also, just FYI, Application->MessageBox() is not thread-safe, so it must be synchronized.另外,仅供参考, Application->MessageBox()不是线程安全的,因此必须同步。 Your 1st call to it is not synchronized, but your 2nd call is.您对它的第一次调用未同步,但您的第二次调用是同步的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM