PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Estring

Hi, edgelib! I've just notice, there is new EString class. I really can't imagine, how it works. Before this I used StrCpy to copy some text into variable.
Lets say, it was:

Code:
ClassEStd::StrCpy(drawtext, "Start Game");

buffer->DrawFont(buffer->GetWidth() / 2, ypos, &shared-;>font, drawtext, EFX_COLORKEY | EFX_COLORIZE | EFO_HCENTER, textcolor);


Now, how would this part of code look like using EString? maybe my question is sort of stupid, but I just wanna know. because "Also, it will handle memory allocation and protection automatically." attracts me a lot.
Hi Ryumaster,

You can create new EString objects, and cast them to WCHAR when using them as a parameter to functions. For example:

Code:

EString test("hello");
ClassEConsole::MsgWindow((WCHAR *)test);


You can even add strings and do more complicated things like:

Code:

ClassEConsole::MsgWindow((WCHAR *)(EString("hello") + "world"));


This creates a new string object, adds another string and casts it to WCHAR.
WOW! That is great! Looks like now I can add cool effects to my dialogs system. I'll take a look on it for sure.
Hi, Edge I have noticed some problems with this class.

The declaration of operator= with EString as parameter is like this

Code:
EString &operator=(EString &str)


instead of

Code:
EString &operator=(const EString &str)


I don't understand why, because the othe two options (with char* and WCHAR*) receive this param as const.

The problem is that I have implemented a Vector class, similar to std::vector, and I have instantiated a Vector< EString >. I can't add an element to this vector because internally my vector calls to operator= wich receives a const &EString param.

If you try something like
Code:

const MenuItem m1;
MenuItem m2;
m2 = m1;


you'll see it doesn't compile because of that operator=. Can you change it?
Btw, EString worked great for me in many cases. But if I supply it as base for filename ( I used WCHAR filename[25] before), I get heap corruption errors. That is not a problem for me, cause I'm using WCHAR for filenames, but just in case You did not know.
Zalo:
The non-const parameter was the cause of an internal issue. The parameter will be constant in the next release.

Ryumaster:
It's odd that the heap corruption issues only occur with files. Could you try the following test (here it works correctly)?

Code:

ClassEFile ef;
if (ef.Open((WCHAR *)(EString(ecd.dat->currentpath) + "test.txt") , EFOF_READ))
{
char filetext[512];
ef.Read(filetext, ef.Size());
filetext[ef.Size()] = 0;
ClassEConsole::MsgWindow(filetext);
ef.Close();
}
There is also a problem with the operators. It seems that
Code:

EString &operator;+(const char *str)
EString &operator;+(const WCHAR *str)
EString &operator;+(const EString &str;)

Are changing the internal value of the object EString when this task in C++ is always delegated to operator+=.
Something like this
Code:
str = str + c;

compiles but thows an exception an instead I have to write
Code:
str + c;

wich looks pretty weird for me
Hi Zalo,

Can you tell me if the issue still occurs with the latest EDGELIB (version 3.60)?

This test here works without any problems:
Code:

//Callback: Called before the display mode changes
ERESULT ClassMain::OnInit(ENATIVETYPE instance)
{
EString str = "hello";
EString c = "world";
str = str + c;
ClassEConsole::MsgWindow((WCHAR *)str);
return(E_OK);
}
Hi, Edge.

It is working fine now. But I still think that operator+ shouldn't modify anything. If you write
Code:
str2 = str1 + c;

both str2 and str1 are modified
Hi, again ^_^

I have a new problem with this class. I have an EString and I am trying to clear it. Something like this:
Code:

EString str1 = "ABCDEF";
str1 = "";

The value for str1 after that is still "ABCDEF". This only happens with "". If I assign " " everything is ok
Hi Zalo,

To temporary fix the empty string assignment problem, we recommend using EString::Trunc to make it empty. We will investigate the other issue with operator+.
Hello, Edge.

I have just updated to the new version (3.60) There is a bug using Series 60 3rd edition when trying to initilize an EString like this:

Code:
EString str = "Hello world";


When I try to compile this with EDGELIB builder I get:

Code:

helloworld.cpp: In member function `virtual long int ClassMain::OnDisplayInit(int, ClassEDisplay*)':
helloworld.cpp:90: error: no matching function for call to `EString::EString(EString)'
C://Develop//Edge//Edge//include/extapi/dataapi.h:70: note: candidates are: EString::EString(EString&)
C://Develop//Edge//Edge//include/extapi/dataapi.h:69: note: EString::EString(const short unsigned int*)
C://Develop//Edge//Edge//include/extapi/dataapi.h:68: note: EString::EString(const char*)
helloworld.cpp:90: error: initializing temporary from result of `EString::EString(const char*)'


It is only happening with series 60 3rd edition. I can compile for pocket pc and series 60 1st edition without any problem. For Series 60 3rd edition I have to write the previous code like this:


Code:
EString str("Hello world");
Hi Zalo,

We've changed the constructor parameter to a const EString, instead of a normal EString. This will fix the compiler issue on Series 60 third edition. It will be available in the next release.
I stumbled on these bugs while using EString as well. Any ETA when the modifiying of s2 in s1=s2+"test" and the s1="" will be fixed?

I also noticed Get() does not returns a const like it should. I wanted to store an EString into EFile and figured I had to use GetDataSize(), but for "test" it returns 5 (4+0-terminated, or 1-byte length indicator+4 chars?). This forced me to make a work-around like this:

Code:

unsigned char iSize=(unsigned char)(sStr.Length()*sizeof(WCHAR));
ef.Write(&iSize,sizeof(iSize));
ef.Write(sStr.Get(),iSize);


(For strings below 128 chars)


For reading from files I had to use:

Code:

unsigned char iSize=0;
ef.Read(&iSize,sizeof(iSize));
WCHAR chr;
/* bugfix since sStr="" does not work
http://www.pocketmatrix.com/forums/viewtopic.php?t=28434 :*/
sStr.Trunc(0);
for(unsigned char i=0;i<iSize;i+=sizeof(WCHAR)) {
ef.Read(&chr,sizeof(WCHAR));
sStr.CatChr(chr);
}


Alternatives would be appreciated :)
Hi Freddy,

Fixes for EString will probably be added in the EDGELIB 3.70 release.

For reading the EString value from a file we recommend allocating memory temporarily and read in the whole string at once.