如何使用windows api中的参数执行TThread?

Ser*_*gey 2 c c++ c++builder

当我创建TThread时我无法将参数传递给线程,所以我需要使用全局变量或者什么?我正在使用Embarcaderos Rad Studio C++ Builder 2010

Joh*_*nck 6

你有一个来自TThread的类,对吗?你能让你的类构造函数采取额外的参数(超出bool suspended似乎常见的那个)吗?


Rob*_*edy 5

提供不同构造函数的另一种方法是在创建对象的时间和启动它的时间之间简单地指定线程的属性.

bool suspended = true;
TSergeyThread* thread = new TSergeyThread(suspended);
thread->Property1 = 4;
thread->SetValue("foo");
thread->Start(); // or ->Resume(), if your VCL is too old
Run Code Online (Sandbox Code Playgroud)

但更好的是在构造函数中提供所有信息.(RAII,以及所有这些.)