IPowerThreadLaunch method

LAUNCH begins execution of the thread, passing parameter data to it. Since the thread is hosted by an object, it is only fitting that the parameter data be contained in the most robust form, another object.

THREADPARAM is a mandatory Instance variable which you must define in each thread class. It is normally declared as the interface name of your choice:

INSTANCE ThreadParam as MyInterface

When the thread begins, PowerBASIC automatically creates a copy of the LAUNCH parameter, and assigns it to ThreadParam. Since it is stored in an Instance variable, it is visible to all of your code in your member methods, yet is kept private from the rest of the program. The use of an object as the parameter is the normally the best choice, as it allows virtually any number of data items to be contained.

In simpler cases, you may choose to declare THREADPARAM as a pointer, Long Integer, or Dword. In that case, you must pass the launch parameter using a byval option, to override the expected object variable.

INSTANCE ThreadParam as LONG

...

MyThread.Launch(ByVal MyNumber&)

Of course, the Pointer parameter option can be used to pass a pointer to any variable, of any type. For example, it could be used to pass a used-defined type if that fits your needs:

INSTANCE ThreadParam AS MyType POINTER

THREAD METHOD MyMethod() AS LONG

xyz# = ThreadParam.member1

... other code

END METHOD

...

MyThread.Launch(ByVal VARPTR(MyType))