Reputation: 13
I am working with the TComPort component by Winsoft. I stored values of some of its properties in a Firebird table and afterwards tried to use them for setting a TComPort instance.
Code is below:
// Storing
IBSQL1->SQL->Clear();
IBSQL1->SQL->Add("Update or insert into FBTable1 (IdTable, DeviceName, BaudRate, DataBits, StopBits, Parity, FlowControlDTR, FlowControlRTS, FlowControlXOnXOff, FlowControlXOffLimit, FlowControlXOnLimit)");
IBSQL1->SQL->Add("values (:IdTable, :DeviceName, :BaudRate, :DataBits, :StopBits, :Parity, :FlowControlDTR, :FlowControlRTS, :FlowControlXOnXOff, :FlowControlXOffLimit, :FlowControlXOnLimit) matching (IdTable)");
IBSQL1->ParamByName("IdTable")->Value = ClientDataSet1->FieldByName("IdTable")->AsInteger;
IBSQL1->ParamByName("DeviceName")->Value = ClientDataSet1->FieldByName("DeviceName")->AsString;
IBSQL1->ParamByName("BaudRate")->Value = ClientDataSet1->FieldByName("BaudRate")->AsString;
IBSQL1->ParamByName("DataBits")->Value = ClientDataSet1->FieldByName("DataBits")->AsString;
IBSQL1->ParamByName("StopBits")->Value = ClientDataSet1->FieldByName("StopBits")->AsString;
IBSQL1->ParamByName("Parity")->Value = ClientDataSet1->FieldByName("Parity")->AsString;
IBSQL1->ParamByName("FlowControlDTR")->Value = ClientDataSet1->FieldByName("FlowControlDTR")->AsString;
IBSQL1->ParamByName("FlowControlRTS")->Value = ClientDataSet1->FieldByName("FlowControlRTS")->AsString;
IBSQL1->ParamByName("FlowControlXOnXOff")->Value = ClientDataSet1->FieldByName("FlowControlXOnXOff")->AsString;
IBSQL1->ParamByName("FlowControlXOffLimit")->Value = ClientDataSet1->FieldByName("FlowControlXOffLimit")->AsInteger;
IBSQL1->ParamByName("FlowControlXOnLimit")->Value = ClientDataSet1->FieldByName("FlowControlXOnLimit")->AsInteger;
IBSQL1->ExecQuery(); IBSQL1->Close();
// Setting
IBSQL1->SQL->Clear();
IBSQL1->SQL->Add("Select DeviceName, BaudRate, DataBits, StopBits, Parity, FlowControlDTR, FlowControlRTS, FlowControlXOnXOff, FlowControlXOffLimit, FlowControlXOnLimit from FBTable1");
IBSQL1->SQL->Add("Where IdTable = 1");
IBSQL1->ExecQuery(); IBSQL1->Close();
ComPort1->DeviceName = IBSQL1->FieldByName("DeviceName")->AsString; // Working
ComPort1->BaudRate = static_cast<TBaudRate *>(IBSQL1->FieldByName("BaudRate")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TBaudRate *'
ComPort1->DataBits = static_cast<TDataBits *>(IBSQL1->FieldByName("DataBits")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TDataBits *'
ComPort1->StopBits = static_cast<TStopBits *>(IBSQL1->FieldByName("StopBits")->AsString); // Not compiling Could not convert type 'UnicodeString' into type 'TStopBits *'
ComPort1->Parity = static_cast<TParity *>(IBSQL1->FieldByName("Parity")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TParity *'
ComPort1->FlowControl->DTR = static_cast<TDTRControl *>(IBSQL1->FieldByName("FlowControlDTR")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TDTRControl *'
ComPort1->FlowControl->RTS = static_cast<TRTSControl *>(IBSQL1->FieldByName("FlowControlRTS")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TRTSControl *'
ComPort1->FlowControl->XOnXOff = static_cast<TXOnXOffControl *>(IBSQL1->FieldByName("FlowControlXOnXOff")->AsString); // Not compiling : Could not convert type 'UnicodeString' into type 'TXOnXOffControl *'
ComPort1->FlowControl->XOffLimit = IBSQL1->FieldByName("FlowControlXOffLimit")->AsInteger; // Working
ComPort1->FlowControl->XOnLimit = IBSQL1->FieldByName("FlowControlXOnLimit")->AsInteger; // Working
The issue is that I don't manage to feed most of the TComPort properties as they are of different type : TBaudRate for the BaudRate, TDataBits for the DataBits, TDTRControl for the FlowControlDTR, TXOnXOffControl for the FlowControlXOnXOff... I tried Static_cast, reinterpret_cast and other similar conversion keywords without success.
Any idea to fix the issue?
Upvotes: 0
Views: 51