473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to assign a textbox control in cpp?

xarzu
88 64KB
I have a silverlight app that uses TextBox XAML controls.

In the c++ code-behind, IXRTextBoxPtr types are associated with these textboxes using "FindName" like this:

FindName(L"ColNum3", &m_pColNum3);

(where ColNum3 corresponds with the XAML CODE like this: )

Then, the code assigns the pointer like this:

std::wstring wsTransfer; // gets the wstring from imput
const WCHAR * wpszInput;
wpszInput = wsTransfer.c_str();
m_pColNum3->SetText(wpszInput);
but the display does not show the text data.

What am I missing? What steps am I missing to have this text modification display on the screen?

If I did not ask this question completely or left something off, please let me know.
Apr 24 '15 #1
3 1767
weaknessforcats
9,208 Expert Mod 8TB
I don't see where it gets the text either.

This code:
Expand|Select|Wrap|Line Numbers
  1. std::wstring wsTransfer;  // gets the wstring from imput
  2.  
creates a wstring object named wsTransfer using the default constructor of wstring--which does not get text.

Then I see:
Expand|Select|Wrap|Line Numbers
  1. const WCHAR * wpszInput;
  2.  wpszInput = wsTransfer.c_str();
This fetches the contents of wsTransfer as a C-style string.

This code:
Expand|Select|Wrap|Line Numbers
  1. m_pColNum3->SetText(wpszInput); 
sets the address of the text into m_pColNUm3.

Nowhere do I see text values.
Apr 24 '15 #2
xarzu
88 64KB
I left out all the details but it gets it.

HRESULT StatsGridControl::SetParsedBoreData(std::vector<st d::vector<std::wstring>> m_vTargetWStringBoreData, std::vector<vPoint5> m_vTargetBoreData)
{
HRESULT hr = S_OK;

std::wstring wsTransfer;
const WCHAR * wpszInput;

for (int iRow = 0; iRow < 4; iRow++)
{
for (int iCol = 0; iCol < 6; iCol++)
{
wsTransfer = m_vTargetWStringBoreData.at(iRow).at(iCol);
wpszInput = wsTransfer.c_str();
switch (iRow)
{
case 0:
if (iCol == 0)
hr = m_pColNum->SetText(wpszInput); // <TextBox x:Name="ColNum">
Apr 24 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. wsTransfer = m_vTargetWStringBoreData.at(iRow).at(iCol);
  2.  wpszInput = wsTransfer.c_str();
retrieves the address of the contents of wsTransfer.

This address is used in:
Expand|Select|Wrap|Line Numbers
  1. hr = m_pColNum->SetText(wpszInput); // <TextBox x:Name="ColNum"> 
Now m_pColNum points to an object that now contains the address of the contents. Unless you can peer into SetText aonc confirm it makes a copy of the text, you have a situation where wsTransfer has gone out of scope and its contents destroyed by its destructor. That leaves the objctec pointed at by m_pColNUm with a address that may or may not work depending upon conditions in memory when you finally get around to displaying the text.

The single most dangerous thing you can do in a C++ program is pass pointers around. C++ is not like C. In C YOU control when the pointer is valid. In C++ the compiler controls it.

The first thing I would do is get out my debugger and step through this code.

The second thing would be to make a copy of the data pointed at by wpszInput. So I could insure the data is there when I need it later.

The third thing would be to install a managed pointer for wpszInput.
Apr 24 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Neil | last post by:
Is there an editable RTF textbox control which allows the user to apply bold, italic, etc.? I tried the Microsoft Rich Textbox Control, but there doesn't seem to be a way to allow the user to...
3
by: hermawih | last post by:
Hi , can anyone help me , please . In Ms Rich textbox control , It is easy to insert object than to insert picture . I want to insert picture in my Ms rtf activeX control but Ms Access does...
3
by: Ryan Joseph So | last post by:
Hi, I've been searching the web for custom textbox control that doesn't inherit from Windows textbox control but cannot find one. I've been trying to make my own custom textbox but I just dont...
5
by: Quan Nguyen | last post by:
How can I obtain the textbox (editing field) control of the combobox? I tried combobox.Controls to obtain the collection of controls that the combobox contains but it turned out to be empty. Thanks.
1
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! Can any one point me in direction of modify a TextBox control. What i want to do is to add a button, like the ComboBox have. with my own bitmap and execute an Event when clicked. I...
4
by: RTM | last post by:
Can anyone help me with the following issue? I've seen some similar questions here, but none relating to a textbox control.... I have a form with several controls, one of them being a textbox...
0
by: Luis Esteban Valencia | last post by:
am trying to databind within an asp:textbox control. I have tried many variations found here but nothing seems to work. It works fine if I use a regular HTML textbox input though. Here is what I...
2
by: fabrice | last post by:
Hi, I have a trouble with my TextBox Control and it's ViewState in my form... The property for it, is FALSE as following : <form id="frmSearchBre4" runat="Server"> <asp:textbox id="myID"...
7
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
7
by: Ned White | last post by:
Is it possible to insert HTML codes to a textbox control ? I am reading HTML formated string from sql server but if i assign this value to Text property of TextBox, the format tags of HTML seems...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.