Home » U++ Library support » LineEdit, EditFields, DocEdit » EditString: how to convert data with "~" operator to char*?
|
|
|
|
Re: Editstring control [message #1391 is a reply to message #1390] |
Thu, 02 March 2006 00:29   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Cpu86 wrote on Wed, 01 March 2006 17:59 | Ok, but I must declare the pointer as a const?
|
I see...
Yes. Constness is needed to give enough freedom for COW String implementations.
If you want to write those chars, you could use StringBuffer:
String x...
StringBuffer xb(x); //Clears x, takes the content
char *x = xb;
// do what you want, investigate StringBuffer interface to learn more
x = xb; // put it back, clears xb
Of course, another option is to simply copy String to separate buffer, however StringBuffer guarantees minimal copying.. (if possible, it performs none).
Mirek
|
|
|
|
|
Re: Editstring control [message #10198 is a reply to message #10173] |
Sun, 24 June 2007 23:16   |
malaugh
Messages: 7 Registered: June 2007
|
Promising Member |
|
|
Fantastic, thanks for your help. I tried your link and it works great. I was able to read out a hex value from the EditFiled after changing the code to do the hex conversion.
There is another issue though. How do I write to the EditField? I thought I could change the FormatIntBase function to base 16, but I ran into problems. Here is part of my code that I was using to debug the problem.
void HexEdit::OnPopulate()
{
int x = 1234;
char s[20];
Value y = 1234;
Value z;
sprintf(s,"%d",x);
z = FormatIntBase(y, 2, 0, 0, 0);
editOutput = s;
// editOutput = x;
// editOutput = y;
// editOutput = z;
}
editOutput is an EditField control. Here is what happens:
editOutput = s; works, it displays 1234
editOutput = x; crashes the program.
editOutput = y; crashes the program.
editOutput = z; works, it displays the binary conversion of 1234
I am not sure why y should fail and z should pass.
Also if I change the code by putting
editOutput.SetConvert(Single<ConvertBin>());
in the initialization (which should call FormatIntBase on a write to the control, and remove FormatIntBase from the populate function, the program crashes.
What am I doing wrong? Any suggestions?
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 13:26:10 CEST 2025
Total time taken to generate the page: 0.00687 seconds
|