B4J Question How to pass custom parameters from on click event to another

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

Hi,

In a B4J Websocket application,

How do you pass a list, or a custom type object, from one click event to another, in the same form? Or in other forms, for that matter?


So in other words, if you have two buttons, and

1) the first button _click method creates and processes a list or a custom type (and it takes 10-60 seconds, e.g.)


2) the second _click method needs one or more of the objects created in the first button _click event. (You want to avoid having to recreate those objects again).


- how do you make those objects available, that were created from the event of one component, to the event methods of other components?
 

stevel05

Expert
Licensed User
Longtime User
You can't pass then explicitly, you could use a global variable.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
You can't pass then explicitly, you could use a global variable.
Hi Steve,

Yes, I know there's no way to pass it as a parameter.

By Global, do you mean a Public variable defined somewhere? I can use that, temporarily.

But one future problem, would be that sometimes the code will need to have multiple objects of the same type. And it might not know, ahead of time, how many of these global objects it will need.

I could put it in a global list, maybe even a stack.

Can you let me know, how you would declare it? Just pick the main routine, and put it there? Or a separate module, that contains only these Public objects?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes add it to a global list (defined in Process Globals) then when you need to access the data you can Get the item at index 0 then use the list.removeAt(0) to create a FIFO stack. Make sure there is something in the list before you read it of course.

Which module you store it in will depend on how many of this sort of object you expect to have. If just a few, put it in the Module that uses it. If I have a lot of data that is not really related to one module, I'll often use a separate code module and call it something like App_Static and put them all in there, the bonus is they are accessible from anywhere.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Yes add it to a global list (defined in Process Globals) then when you need to access the data you can Get the item at index 0 then use the list.removeAt(0) to create a FIFO stack. Make sure there is something in the list before you read it of course.

Which module you store it in will depend on how many of this sort of object you expect to have. If just a few, put it in the Module that uses it. If I have a lot of data that is not really related to one module, I'll often use a separate code module and call it something like App_Static and put them all in there, the bonus is they are accessible from anywhere.

Sounds workable, thanks.
 
Upvote 0
Top