Best way to contain reusable code in app?

Andrew2009

Well Known Member
Right now if I have something that will be used by more than one form control then I create a button (hidden) and put this logic into it. All other form controls will call this button. Is this the most common thing to do for reusable code? I'm looking for best practice. Thanks
 

BOster

Legendary Poster
Yes. You can use a hidden button like a "subroutine" for lack of a better term. I use that technique quite extensively. Only bad thing is that the only way to "pass args" to the "subroutine" is by frm scope variables - so you may end up with a lot of global scope variables. In powerforms there is also the ability to create actual form functions. I have used them some but found that hidden buttons tend to work better (I can't recall why at the moment). One advantage of the form function is that you can call it from another form (although it only acts on variables/controls for the form that it is attached to). But I have found that a message system using powerforms is better (form "listens" for message and runs logic on hidden button, etc.) than form functions.

If it is business logic I would suggest a BSFN. I use BSFNs for pretty much all business logic and only use ER code for presentation/UI.
 

johndanter

Legendary Poster
Yes, nothing wrong with a button, providing all other 'forms' can access it. But I would put it in a NER BSFN.
As you may find you'll want this code to be used elsewhere, like in a UBE or even another form altogether.
 
Top