Problems with DCTOOLBAR and DCADDBUTTON

This forum is for eXpress++ general support.
Post Reply
Message
Author
Viktor
Posts: 4
Joined: Mon Sep 11, 2017 11:29 am

Problems with DCTOOLBAR and DCADDBUTTON

#1 Post by Viktor »

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?

User avatar
hz_scotty
Posts: 107
Joined: Thu Jan 28, 2010 8:20 am
Location: Wr.Neustadt / Österreich

Re: Problems with DCTOOLBAR and DCADDBUTTON

#2 Post by hz_scotty »

show some code from the buttons, please :!:
best regards
Hans

Viktor
Posts: 4
Joined: Mon Sep 11, 2017 11:29 am

Re: Problems with DCTOOLBAR and DCADDBUTTON

#3 Post by Viktor »

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?

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Problems with DCTOOLBAR and DCADDBUTTON

#4 Post by Cliff Wiernik »

Try expanding the oToolBar Size to account for more buttons.

Viktor
Posts: 4
Joined: Mon Sep 11, 2017 11:29 am

Re: Problems with DCTOOLBAR and DCADDBUTTON

#5 Post by Viktor »

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?

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: Problems with DCTOOLBAR and DCADDBUTTON

#6 Post by reganc »

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?
It mentions in the docs, DCADDBUTTONXP uses the same parameters as the @ DCPUSHBUTTONXP command.
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

User avatar
Tom
Posts: 1170
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problems with DCTOOLBAR and DCADDBUTTON

#7 Post by Tom »

Hi, Viktor.
How can I do this?
Look's like you're trying to do something like 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
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:

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
This works, but it's not very elegant. This will work aswell:

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
[/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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1170
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problems with DCTOOLBAR and DCADDBUTTON

#8 Post by Tom »

Add: If you just need/evaluate the button caption, you may do this:

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
The button itself is the third parameter handed to the ACTION codeblock. "Caption" is the iVar holding the button caption.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Viktor
Posts: 4
Joined: Mon Sep 11, 2017 11:29 am

Re: Problems with DCTOOLBAR and DCADDBUTTON

#9 Post by Viktor »

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

Wolfgang Ciriack
Posts: 479
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Problems with DCTOOLBAR and DCADDBUTTON

#10 Post by Wolfgang Ciriack »

A Action block like

Code: Select all

{|a,b,o| retwert:=o:caption, DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}
and return the retwert from this function should do this.
_______________________
Best Regards
Wolfgang

Post Reply