Reply To: Passing multiple args to a tcl proc in one variable

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Passing multiple args to a tcl proc in one variable Reply To: Passing multiple args to a tcl proc in one variable

#57029
Troy Morton
Participant

I personally prefer keyed lists.  This allows you to add or remove arguments to the proc without affecting the fucntionality or compatibility if the proc is being used in multiple places .. like so ..

Code:


         #
         # Populate the arguments to send to the proc SendEmailMessage
         # and call the proc.
         #
         keylset mailargs MH         $mh
         keylset mailargs TOFILE     $blnTrcWrite
         keylset mailargs HOSP       $msghosp
         keylset mailargs MAILTO     $mailto
         keylset mailargs MAILFROM   $mailfrom
         keylset mailargs MAILSUBJ   $mailsubj
         keylset mailargs MAILMSG    $mailmsg
         keylset mailargs MAILSERVER $mailserver
         keylset mailargs MAILDOMAIN $maildomain
         keylset mailargs MAILSTART  $mailstart
         keylset mailargs MAILSTOP   $mailstop

         SendEmailMessage $mailargs

… and in the called proc get the data out of the argument keyed list …

Code:


proc SendEmailMessage { mailargs } {

   keylget mailargs         MH mh
   keylget mailargs     TOFILE blnTrcWrite
   keylget mailargs       HOSP hosp
   keylget mailargs     MAILTO mailto
   keylget mailargs   MAILFROM mailfrom
   keylget mailargs   MAILSUBJ mailsubj
   keylget mailargs    MAILMSG mailmsg
   keylget mailargs MAILSERVER mailserver
   keylget mailargs MAILDOMAIN maildomain
   keylget mailargs  MAILSTART mailstart
   keylget mailargs   MAILSTOP mailstop

As I mentioned this gives you alot of flexibility to add or remove arguments and functionality to a proc while keeping it backwards compatible with other places its being used.

Also, it doesn’t matter what order you supply the arguments because the list is keyed.  So, you don’t have to remember that the first argument is X and the second is Y the third is Z and take a chance of putting them in the wrong order when calling the proc.

Hope this helps

Forum Statistics

Registered Users
5,116
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10