|
-
April 26th, 1999, 10:42 PM
#1
Converting CString to type VARIANT
I'm transferring a number of values from an Array to an OLE grid control (XGrid). The OLE object requires the value to be passed as typr VARIANT which I initialized as follows :
// Initialize Variables
int row, col;
tagVARIANT CellValue;
::VariantInit(&CellValue);
A Number of loops loads each column based on a user selection. Each column is either of type CString or int but they all need to be converted to type VARIANT which works ok for type int
// Load Skill Ability->Skill
col = 3;
for(row=2;row<SKILL_COUNT;row++)
{
CellValue.intVal = GetDocument()->m_Skills.GetSkillAbilitySkill(row-1);
m_XGrid4.TargetCell(row, col);
m_XGrid4.SetValue(CellValue);
}
For my CString columns I get the following message : <'binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)>. I tried a number of types for VARIANT including bstrVal, cVal etc.
Thank you for you suggestions.
Pras
-
April 26th, 1999, 10:53 PM
#2
Re: Converting CString to type VARIANT
I am not sure I follow exactly what you are doing there, but I would suggest that you use a COleVariant class. It can automatically convert from many different data types.
--michael
-
April 26th, 1999, 11:42 PM
#3
Re: Converting CString to type VARIANT
Here's one option:
// str is a CString
COleVariant var(str.GetBuffer(), VT_BSTRT);
VARIANT var2 = var.Detach();
// now pass var2 to your function needing a VARIANT
-
April 26th, 1999, 11:45 PM
#4
Re: Converting CString to type VARIANT
Thank you - works well :-)
Pras
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|