getting a panic while appending a string

Login to reply to this topic.
Tue, 2008-03-04 17:09
Joined: 2007-09-19
Forum posts: 18

Hi,

I am doing a program to append a string to the other one. but am getting a panic "Applicatoin closed"..

My code is:

HBufC* Buf = StringLoader::LoadLC(R_HEWB_COMMAND1_TEXT ); // loading

// string from the resource.

StrDisplay(Buf); // my own function to display a string
CleanupStack::PopAndDestroy( Buf );
_LIT(KNew, " New");
TPtr Pointer = Buf->Des();
Pointer.Append(KNew);
StrDisplay(Buf);

// function to display a string.
void CHelloWorldBasicAppUi:: StrDisplay(HBufC* Buf)
{
CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
note->ExecuteLD( *Buf );

}

Its working fine when i display a single string but gives a panic whenever i append a new string..

Plz help me in finding the error...

thanx in advance..


Tue, 2008-03-04 18:10
Joined: 2007-04-10
Forum posts: 17
Re: getting a panic while appending a string

I don't know the error, but you can try this code

// Concatenate a string
void AddStringL(HBufC8 **aStrOrg, const TDesC8 &aStrToAdd) {
if (!*aStrOrg) {
*aStrOrg = aStrToAdd.AllocL();
} else {
*aStrOrg = (*aStrOrg)->ReAllocL((*aStrOrg)->Des().Length() + aStrToAdd.Length());
(*aStrOrg)->Des().Append(aStrToAdd);
}
}

// Concatenate a string
void AddStringL(HBufC **aStrOrg, const TDesC &aStrToAdd) {
if (!*aStrOrg) {
*aStrOrg = aStrToAdd.AllocL();
} else {
*aStrOrg = (*aStrOrg)->ReAllocL((*aStrOrg)->Des().Length() + aStrToAdd.Length());
(*aStrOrg)->Des().Append(aStrToAdd);
}
}

// Concatenate a string
void AddStringL(HBufC8 **aStrOrg, const TDesC &aStrToAdd) {
if (!*aStrOrg) {
*aStrOrg = HBufC8::NewL(aStrToAdd.Length());
(*aStrOrg)->Des().Copy(aStrToAdd);
} else {
*aStrOrg = (*aStrOrg)->ReAllocL((*aStrOrg)->Des().Length() + aStrToAdd.Length());
(*aStrOrg)->Des().Append(aStrToAdd);
}
}

// Concatenate a string
void AddStringL(HBufC **aStrOrg, const TDesC8 &aStrToAdd) {
if (!*aStrOrg) {
*aStrOrg = HBufC::NewL(aStrToAdd.Length());
(*aStrOrg)->Des().Copy(aStrToAdd);
} else {
*aStrOrg = (*aStrOrg)->ReAllocL((*aStrOrg)->Des().Length() + aStrToAdd.Length());
HBufC *temp = HBufC::NewL(aStrToAdd.Length());
temp->Des().Copy(aStrToAdd);
(*aStrOrg)->Des().Append(*temp);
delete temp;
}
}

Tue, 2008-03-04 19:46
Joined: 2004-09-14
Forum posts: 140
Re: getting a panic while appending a string

well, perhaps a Symbian fresher course is in order for you two.....

CleanupStack::PopAndDestroy( Buf );
_LIT(KNew, " New");
You just destroyed Buf above, yet you use it below!!!
TPtr Pointer = Buf->Des();


Paul Todd

  • Login to reply to this topic.