Sergey
Sergey

Reputation: 685

how to execute TThread with parameter like in windows api?

When i creating TThread i can't pass parameters to thread, so i need use global variables or what? I am using Embarcaderos Rad Studio C++ Builder 2010

Upvotes: 2

Views: 1039

Answers (2)

Rob Kennedy
Rob Kennedy

Reputation: 163287

An alternative to providing a different constructor is to simply assign properties of the thread between the time you create the object and the time you start it.

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

Better is to provide all that information in the constructor, though. (RAII, and all that.)

Upvotes: 5

John Zwinck
John Zwinck

Reputation: 249223

You have a class derived from TThread, right? Can you just make your class constructor take additional arguments (beyond the bool suspended one that seems to be common)?

Upvotes: 6

Related Questions