View previous topic :: View next topic |
Author |
Message |
yidabu
Joined: 21 Apr 2007 Posts: 87
|
Posted: Sun Mar 30, 2008 2:17 am Post subject: 0 terminated string of (*HJson.value).toString |
|
|
here is a example:
Code: | if( auto ele = rootElement.getId("textarea_id".dup) )
{ auto str = (*ele.value).toString;
Trace.formatln("string {}", str);
} |
I use this trick to remove the null everywhere:
Code: | if(str.length && str[$-1] is '\0')
{
str.length = str.length -1;
} |
_________________ D yuyan |
|
Back to top |
|
|
bobef
Joined: 05 Jun 2005 Posts: 269
|
Posted: Sun Mar 30, 2008 1:19 pm Post subject: |
|
|
Thanks. I will fix this in the next release. Also, you will no longer need to write (*ele.value).toString but ele.value.toString will be fine. By the way, why do you need .dup in here rootElement.getId("textarea_id".dup)? |
|
Back to top |
|
|
yidabu
Joined: 21 Apr 2007 Posts: 87
|
Posted: Sun Mar 30, 2008 4:48 pm Post subject: |
|
|
bobef wrote: | Thanks. I will fix this in the next release. Also, you will no longer need to write (*ele.value).toString but ele.value.toString will be fine. By the way, why do you need .dup in here rootElement.getId("textarea_id".dup)? |
thx a lot!
I used a HWND to load two sourc.htm, I have not lucky to figured out some issues, e.g., click button a, but button b has been executed, so I tried add .dup to string, tried add sleep(seconds) before OnDomready .... to see the result.
subclass your HLayoutControl class for every HWND now, seems ok. _________________ D yuyan |
|
Back to top |
|
|
bobef
Joined: 05 Jun 2005 Posts: 269
|
Posted: Mon Mar 31, 2008 12:54 am Post subject: |
|
|
For buttons you can do something like this: Code: | myButton.handleEvent(delegate(HBehaviorEvent e)
{
if(e.cmd==BUTTON_CLICK) {return true;//dome something}
else return false;
}); |
|
|
Back to top |
|
|
yidabu
Joined: 21 Apr 2007 Posts: 87
|
Posted: Mon Mar 31, 2008 5:31 am Post subject: |
|
|
bobef wrote: | For buttons you can do something like this: Code: | myButton.handleEvent(delegate(HBehaviorEvent e)
{
if(e.cmd==BUTTON_CLICK) {return true;//dome something}
else return false;
}); |
|
is it possible one delegate to handle all button events?
Code: | buttons.handleEvent(delegate(HBehaviorEvent e)
{
if(e.cmd==BUTTON_CLICK)
{
if(p.element["link"])
//navigateTo(p.element["link"]);
return true;//dome something
}
else return false;
});
|
to handle hundreds of elements event (e.g. tree view, every li is a link) manually, it's nightmare. _________________ D yuyan |
|
Back to top |
|
|
bobef
Joined: 05 Jun 2005 Posts: 269
|
Posted: Mon Mar 31, 2008 11:31 am Post subject: |
|
|
Sure.
Code: | bool myDelegate(HBehaviorEvent p)
{
//dosomething
}
HElement[100] myelements;
foreach(m;myelements) m.handleEvent(&myDelegate); |
Keep in mind that if you are using handleEvent you must keep a reference to the HElement somewhere, otherwise the GC could wipe out your event. If you are not keeping a reference you can use handleStatic instead of handleEvent. This way the handler will persist as long as underlaying HELEMENT is not destroyed by HTMLayout. |
|
Back to top |
|
|
|