Problems with DCTOOLBAR and DCADDBUTTON
Problems with DCTOOLBAR and DCADDBUTTON
I am new to express ++. I'm testing the xdemo program and I would like to add more buttons to the top toolbar with DCADDBUTTON. Xdemo always displays only the first two buttons, while the other five are not displayed. What am I doing wrong?
Re: Problems with DCTOOLBAR and DCADDBUTTON
show some code from the buttons, please

best regards
Hans
Hans
Re: Problems with DCTOOLBAR and DCADDBUTTON
Code is from original folder Express++ >samples >xdemo
program xdemo.prg
// Top Statusbar
DCSTATUSBAR oStatTop HEIGHT 31 ALIGN DCGUI_ALIGN_TOP ;
HELPCODE '.STATUSBAR_TOP' ;
HIDE {||Empty(oToolBar:childList())}
@ 0,0 DCTOOLBAR oToolBar SIZE 1000,31 PIXEL PARENT oStatTop ;
BUTTONSIZE 32,31 HELPCODE '.TOOLBAR_TOP' FANCY ;
TYPE XBPSTATIC_TYPE_TEXT ;
EVAL {|o|o:setColorBG(DC_XbpMenuConfig()[10])}
DCADDBUTTON CAPTION BITMAP_TREE_M PARENT oToolbar ; //original code
ACTION {|o|o:=Thread():new(),o:start({|| TreeMenu()})} ;
TOOLTIP 'Tree-View style menu;Build custom Tool-Bar'
DCADDBUTTON CAPTION '&Open' PARENT oToolBar PIXEL ; //button added in oToolBar
TOOLTIP 'Exit'
DCADDBUTTON CAPTION '&Exit' PARENT oToolBar PIXEL ;
TOOLTIP 'Exit'
What I'm doing wrong?
program xdemo.prg
// Top Statusbar
DCSTATUSBAR oStatTop HEIGHT 31 ALIGN DCGUI_ALIGN_TOP ;
HELPCODE '.STATUSBAR_TOP' ;
HIDE {||Empty(oToolBar:childList())}
@ 0,0 DCTOOLBAR oToolBar SIZE 1000,31 PIXEL PARENT oStatTop ;
BUTTONSIZE 32,31 HELPCODE '.TOOLBAR_TOP' FANCY ;
TYPE XBPSTATIC_TYPE_TEXT ;
EVAL {|o|o:setColorBG(DC_XbpMenuConfig()[10])}
DCADDBUTTON CAPTION BITMAP_TREE_M PARENT oToolbar ; //original code
ACTION {|o|o:=Thread():new(),o:start({|| TreeMenu()})} ;
TOOLTIP 'Tree-View style menu;Build custom Tool-Bar'
DCADDBUTTON CAPTION '&Open' PARENT oToolBar PIXEL ; //button added in oToolBar
TOOLTIP 'Exit'
DCADDBUTTON CAPTION '&Exit' PARENT oToolBar PIXEL ;
TOOLTIP 'Exit'
What I'm doing wrong?
-
- Posts: 605
- Joined: Thu Jan 28, 2010 9:11 pm
- Location: Steven Point, Wisconsin USA
- Contact:
Re: Problems with DCTOOLBAR and DCADDBUTTON
Try expanding the oToolBar Size to account for more buttons.
Re: Problems with DCTOOLBAR and DCADDBUTTON
Even if I Expanding the oToolBar Size, only two buttons are displayed.
Now I have a new problem. I have the buttons created (DCADDBUTTONXP) with FOR loop and now I need to figure out which button was pressed. Which DCADDBUTTONXP parameter returns, for example, a button caption or button reference? How can I do this?
Now I have a new problem. I have the buttons created (DCADDBUTTONXP) with FOR loop and now I need to figure out which button was pressed. Which DCADDBUTTONXP parameter returns, for example, a button caption or button reference? How can I do this?
Re: Problems with DCTOOLBAR and DCADDBUTTON
It mentions in the docs, DCADDBUTTONXP uses the same parameters as the @ DCPUSHBUTTONXP command.Viktor wrote:Even if I Expanding the oToolBar Size, only two buttons are displayed.
Now I have a new problem. I have the buttons created (DCADDBUTTONXP) with FOR loop and now I need to figure out which button was pressed. Which DCADDBUTTONXP parameter returns, for example, a button caption or button reference? How can I do this?
So you can add an ID clause to give the button a name and also add an OBJECT clause to put the button object into a variable.
You can then use 'cID := dc_getobjectid(oOBJECT)' to get the ID and use 'cCaption := oOBJECT:caption' to get the caption.
Does that help?
By the way, you will get more help with your other issues if you can post your small test program showing the issues you are having to allow someone else to build it and have a look.
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com
Real Business Applications Ltd
http://www.rbauk.com
Re: Problems with DCTOOLBAR and DCADDBUTTON
Hi, Viktor.
You will get 3 buttons with the captions 'Button 1' ... 'Button 3', since the CAPTION clause will be evaluated while the buttons are created. But the ACTION will fail, since this code is evaluated when the button is pressed (!). The variable 'i' is 4 in that situation, not 1, 2 or 3.
There are several ways to solve this. The easiest is this one:
This works, but it's not very elegant. This will work aswell:
[/code]
It's a little more elegant, as long as "MyFunction" is not a STATIC function, but the best way would be to use detached/anchored codeblocks.
Look's like you're trying to do something like this:How can I do this?
Code: Select all
aButtons := {'Button 1','Button 2',Button 3'}
FOR i := 1 TO Len(aButtons)
DCADDBUTTON CAPTION aButtons[i] ACTION {||MyFunction(i)} PARENT oButtons
NEXT
There are several ways to solve this. The easiest is this one:
Code: Select all
aButtons := {{'Button 1',{||MyFunction(1)}},;
{'Button 2',{||MyFunction(2)}},;
{'Button 3',{||MyFunction(3)}}}
FOR i := 1 TO Len(aButtons)
DCADDBUTTON CAPTION aButtons[i,1] ACTION aButtons[i,2] PARENT oButtons
NEXT
Code: Select all
[code]aButtons := {'Button 1','Button 2',Button 3'}
FOR i := 1 TO Len(aButtons)
bButtAction := &("{||MyFunction("+Str(i,1,0)+")}")
DCADDBUTTON CAPTION aButtons[i] ACTION bButtAction PARENT oButtons
NEXT
It's a little more elegant, as long as "MyFunction" is not a STATIC function, but the best way would be to use detached/anchored codeblocks.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Problems with DCTOOLBAR and DCADDBUTTON
Add: If you just need/evaluate the button caption, you may do this:
The button itself is the third parameter handed to the ACTION codeblock. "Caption" is the iVar holding the button caption.
Code: Select all
aButtons := {'Button 1','Button 2',Button 3'}
FOR i := 1 TO Len(aButtons)
DCADDBUTTON CAPTION aButtons[i] ACTION {|a,b,o|MsgBox(o:Caption)} PARENT oButtons
NEXT
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Problems with DCTOOLBAR and DCADDBUTTON
The code works perfectly, especially the third example.
Thank you for your guidance.
Is it possible that when I select this button, I get the caption bask (as in the example described) and at the same time closes the subdialog with the defined buttons? Or is it necessary action with an additional button in the subdialog?
Thanks in advance
Thank you for your guidance.
Is it possible that when I select this button, I get the caption bask (as in the example described) and at the same time closes the subdialog with the defined buttons? Or is it necessary action with an additional button in the subdialog?
Thanks in advance
-
- Posts: 484
- Joined: Wed Jan 27, 2010 10:25 pm
- Location: Berlin Germany
Re: Problems with DCTOOLBAR and DCADDBUTTON
A Action block like
and return the retwert from this function should do this.
Code: Select all
{|a,b,o| retwert:=o:caption, DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}
_______________________
Best Regards
Wolfgang
Best Regards
Wolfgang