Board index » cppbuilder » Disappearing AnsiStrings

Disappearing AnsiStrings


2005-04-30 12:28:21 AM
cppbuilder91
I have a class which has AnsiStrings as class members:
class MyClass
{
protected:
AnsiString strName;
AnsiString strConfigName;
public:
MyClass( AnsiString strNewName );
}
In the constructor, I initialize the string members:
MyClass::MyClass( AnsiString strNewName )
{
strName = strNewName;
strConfigName = "PrependedInformation";
strConfigName += strNewName;
}
When I single-step through this, strNewName has the correct value.
strName and strConfigName are empty strings on entry to the constructor,
as expected, but never get anything stored into them: they are still
empty strings at the end of the function.
So I added this:
MyClass::MyClass( AnsiString strNewName )
{
AnsiString strMyName = strNewName;
strName = strMyName;
....
}
strMyName is initialized with the correct value from strNewName.
strName remains an empty string.
I'm baffled. This code worked at one time; now it doesn't.
Thanks for any help that anyone can give!
Dan.
 
 

Re:Disappearing AnsiStrings

On Fri, 29 Apr 2005 09:28:21 -0700, Dan Wilson wrote:
Quote
Thanks for any help that anyone can give!
I'd be baffled too. This is what I did, and it worked just fine (bcb6)
class MyClass
{
protected:
AnsiString strName;
AnsiString strConfigName;
public:
MyClass( AnsiString strNewName );
AnsiString GetConfigName() { return strConfigName; };
};
MyClass::MyClass( AnsiString strNewName ) : strName(strNewName)
{
strName = strNewName;
strConfigName = "PrependedInformation" + strNewName;
}
--
Good luck,
liz
 

Re:Disappearing AnsiStrings

Dan Wilson wrote:
Quote
I have a class which has AnsiStrings as class members:

class MyClass
{
protected:
AnsiString strName;
AnsiString strConfigName;

public:
MyClass( AnsiString strNewName );
}

In the constructor, I initialize the string members:

MyClass::MyClass( AnsiString strNewName )
{
strName = strNewName;
strConfigName = "PrependedInformation";
strConfigName += strNewName;
}

When I single-step through this, strNewName has the correct value.
strName and strConfigName are empty strings on entry to the
constructor, as expected, but never get anything stored into them:
they are still empty strings at the end of the function.

So I added this:

MyClass::MyClass( AnsiString strNewName )
{
AnsiString strMyName = strNewName;
strName = strMyName;
....
}

strMyName is initialized with the correct value from strNewName.
strName remains an empty string.

I'm baffled. This code worked at one time; now it doesn't.

Thanks for any help that anyone can give!

Have you changed other parts of your program recently?
I encountered a similar problem a year or so back. The problem turned
out to be some other code that was called before the code where the
problem showed up. The offending code did pointer molestation (in my
case, falling off the end of an array because of an error mapping
indices). However, anything squirrelly with a pointer (eg
dereferencing a NULL, etc) could potentially do something similar.
 

{smallsort}

Re:Disappearing AnsiStrings

Dan Wilson < XXXX@XXXXX.COM >writes:
Quote
I'm baffled. This code worked at one time; now it doesn't.
Sounds like a build problem.
However, if you still reproduce it after clearing out all the
intermediate files, then try to post a program that will demonstrate
this. I understand that non-deterministic problems are hard to
reproduce, but if you can demonstrate complete code that does show the
problem (even for us), that'd go a long way toward getting better help
or hopefully even getting it fixed.
--
Chris (TeamB);