RedHat
RedHat

Reputation: 205

Calling the ButtonClicked event

I have a script below under a datawindow's buttonclicked event. My problem is how will I call the specific button from other event like parent window post_open event.

In windows post_open event I have the script but returns Bad Argument List For Function: buttonclicked message when I compile. How can I correct this compilation error?

dw_Command.Event buttonclicked('b_read')


DWO: Datawindow
Event: buttonclicked

CHOOSE CASE Lower(dwo.Name)

CASE 'b_read'       

        SetPointer(Hourglass!)
        idt_ServerDate = gnv_app.of_getServerDate( )
        of_getInventoryAdvice( )

CASE 'b_exit'       
        MessageBox('','Close')
        Close(Parent) 

END CHOOSE

Upvotes: 2

Views: 8541

Answers (2)

Terry
Terry

Reputation: 6215

The correct answer to the asked question has been given, but I'm going to propose a contrarian point of view: that you should (virtually) never do what you're asking. When you get functionality implemented in a system event that needs to be called from another system event, you should probably break that functionality into a separate custom user event (or function) and call it from both places. Why?

  1. Syntax is easier (as evidenced by the existence of this question).
  2. It's easier to maintain code when you know when it's going to be called. And for the person that takes over for you after you win the lottery.
  3. Today the required functionality is identical, but sooner or later it will branch. Or someone will try to implement something in the ancestor ButtonClicked, thinking it's only going to fire when there's a button clicked. (I know. Some people are crazy like that.) Then you'll end up with some spaghetti solution to keep track of whether this is a non-button-clicked ButtonClick.... Ugly. Then, sooner or later, someone gets hurt.

At one point, I'm sure it seemed easier to just call ButtonClicked. I'm betting you're already teetering on the edge of that decision, and with a little imagination, I'm hoping you'll split apart the script into something more modular. Never regretted breaking something apart...

Good luck,

Terry.

Upvotes: 4

Seki
Seki

Reputation: 11465

Bad Argument List For Function: buttonclicked

That message is telling you that you are not passing the correct type and /or number of arguments to the function (or event).

The ButtonClicked event is expecting 3 arguments that you must emulate if you want to call it yourself:

  • row a row number where the button has been called
  • ReturnCode a long value that is returned by the action performed by the button
  • dwo a datawindow object. It is a a reference to the control that was "clicked" by the mouse pointer, you can pass a dw.object.name_of_your_button

You could try with the following:

long ll_arc
dw_Command.event buttonclicked( dw_Command.getrow(), ll_arc, dw_Command.object.b_read )

Upvotes: 2

Related Questions