Table methods

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Table methods

Postby Morley » Tue Aug 24, 2004 9:52 pm

There are some methods I'd like to have available for all forms within a particular table. I've been duplicating, one by one, a set attached to one of the existing forms. Later I'll begin attaching them to particular fields, buttons, onShow, onHide etc.

By working this way is there a feature or coding strategy I'm missing?

I'd far prefer having a single set of methods attached to the table in much the same way as global methods are attached to all forms throughout the solution. With table methods any change made would apply to all instances they're called throughout that table. I'd not have to remember to change each of the methods on each of the forms within that table.

Anyone have thoughts on this theme?
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby bcusick » Tue Aug 24, 2004 10:57 pm

Hi Morley,

Just make a global "onShow" method and attach to all the applicable forms.

:D

For example: "onShow_Customer" - you can attach that to all forms based on the customer table, etc.

Is that what you meant?

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby Morley » Wed Aug 25, 2004 1:39 am

bcusick wrote:Hi Morley,

Just make a global "onShow" method and attach to all the applicable forms.

:D

For example: "onShow_Customer" - you can attach that to all forms based on the customer table, etc.

Is that what you meant?

Bob Cusick
Not really. I'm including the same portals on several forms of one particular table. Many of the fields on these portals call for methods for onFocusGained and/or onFocusLost, onAction, and so forth. Unlikely to be used on the forms of any other table.

Therefore I'm currently duplicating these same set of methods from one form to the next to the next. While doing this I noticed an error in one of these methods. Which meant going back and fixing all the other copies. Shades of FMP.

Sounds like there's no more efficient way of handling this than the way I'm doing it.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby bcusick » Wed Aug 25, 2004 4:35 pm

Morley,

If you need different functionality for each field on each form, then you DO have to create separate methods. HOWEVER, you can take the parts of the methods that are the SAME and make a single global method and call it. For example, say you wanted to show a dialog when there was an error. Rather than placing this code:

Code: Select all
plugins.dialogs.showErrorDialog( 'Error',  'Sorry, an error happened.',  'OK')


in EVERY method - you can make a GLOBAL method called "dialog_error" and CALL that method from other methods. For example:

Code: Select all
if(field1 != field2)
{
     globals.dialog_error
}


AND - to get more "fancy" - every method in JavaScript can pass and accept arguments. So, if you wanted to display a custom message - you can change the code for dialog_error to:

Code: Select all
plugins.dialogs.showErrorDialog( 'Error',  'Sorry, an error happened: ' + arguments[0],  'OK')


The "arguments[0]" part will display the first parameter that's passed. Now we change the code in our triggering method to:

Code: Select all
if(field1 != field2)
{
     globals.dialog_error('Custom Error Message Here')
}


If you do this - you can keep all the "common" code in global methods that you can call from anywhere and reduce the number of "places" you have to update code.

Hope this helps,

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 41 guests

cron