I have a problem with converting a string variable to TObject.
I have a query that returns two columns to me. In the first column I have varchar values that I translate into strings, and in the second column I have int values.
I want to fill a ComboBox in this way with these values:
cbx1-> AddItem (DataSet1->DataSet->Fields->Field[0]->AsString, (TObject *) (int) DataSet1->DataSet->Fields->Field[1];
As I refer to the second value which is int type, I receive some bushes, e.g., xD, etc.
By trying to convert this value to string, eg:
String temp = IntToStr (DataSet1->DataSet->Fields->Field[1]);
cbx1-> AddItem (DataSet1->DataSet->Fields->Field[0]->AsString, (TObject *) temp;
I receive an error message:
cannot cast from 'AnsiString' to 'TObject'
I do not know what further I can do to convert this value.
You cannot cast an
AnsiStringvalue to aTObject*pointer. You can only cast an integer value, or a pointer value, to aTObject*pointer.AnsiStringis neither of those.You are not retrieving the
intvalue from the 2nd field correctly anyway.Field[1]is a pointer to an actualTFieldobject in theFieldscollection. That pointer is what you are trying to store in your ComboBox, NOT theintvalue that theTFieldrepresents.You need to call
Fields[1]->AsIntegerto get theintvalue of the 2nd field, similar to how you useFields[0]->AsStringto get the string value of the 1st field:This is no different than the code in your previous question:
You are now just placing the literals
"one"and1with runtime variables of equivalent types.