Hello,
I am using Embarcadero C++ Builder XE5 and the latest WCL for VCL.
When i create TwclAPI, TwclBluetoothDiscovery and TwclClient over the IDE in a Form, everything works fine.
I can connect to other devices and event handlers like OnConnect or OnData are called correctly.
Since it is common, that we are using threads for automated things, i want to use WCL in threads.
Therefore i created objects like this:
class BluetoothThread : public TThread
{
private:
TwclBluetoothRadio* __fastcall GetSelectedRadio();
protected:
void __fastcall Execute();
void __fastcall DoTerminate();
public:
TwclAPI *wclAPI1;
TwclBluetoothDiscovery *wclBluetoothDiscovery1;
TwclClient *wclClient1;
void __fastcall wclClient1Connect(TObject *Sender, int Error);
void __fastcall wclClient1Disconnect(TObject *Sender);
__fastcall BluetoothThread();
__property Terminated;
};
TwclBluetoothRadio* __fastcall BluetoothThread::GetSelectedRadio()
{
TwclBluetoothRadio* Result = NULL;
TwclBluetoothRadios* Radios = new TwclBluetoothRadios();
if (!wclShowError(wclBluetoothDiscovery1->EnumRadios(Radios)) && Radios->Count > 0)
{
Result = new TwclBluetoothRadio();
Result->Assign(Radios->Items[0]);
}
return Result;
}
void __fastcall BluetoothThread::Execute()
{
wclAPI1 = new TwclAPI(NULL);
wclBluetoothDiscovery1 = new TwclBluetoothDiscovery(NULL);
wclClient1 = new TwclClient(NULL);
wclClient1->OnConnect = wclClient1Connect;
wclClient1->OnDisconnect = wclClient1Disconnect;
wclClient1->BluetoothParams->Authentication = false;
wclClient1->BluetoothParams->Channel = 0;
wclClient1->BluetoothParams->Encryption = false;
wclClient1->BluetoothParams->Address = "(D4:94:A1:54:32:8F)";
wclClient1->BluetoothParams->Radio = Radio;
wclClient1->BluetoothParams->Service = SerialPortServiceClass_UUID;
wclClient1->ConnectTimeout = 20000;
wclClient1->Transport = trBluetooth;
wclAPI1->Load();
TwclBluetoothRadio* Radio = GetSelectedRadio();
if (Radio)
{
wclShowError(wclClient1->Connect());
Radio->Free();
}
......
My problem is, that when i try to connect the wclClient1, it stays in FState = scConnecting and never reaches the event handler OnConnect.
What could be wrong here?
Maybe i need to change the method creating WCL objects?
Thanks for any help
madjoe