Home > Community > Forums > Custom IC SKILL > How to write inline callback methods

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 How to write inline callback methods 

Last post Wed, Apr 10 2013 4:30 AM by TauStudent. 3 replies.
Started by TauStudent 09 Apr 2013 11:13 PM. Topic has 3 replies and 742 views
Page 1 of 1 (4 items)
Sort Posts:
  • Tue, Apr 9 2013 11:13 PM

    How to write inline callback methods Reply

    Hello,
    I'm writing a Form in skill for a university project, many of the controls in my form have a callback method which is very short
    Example :


     EnableEddyRadioField = hiCreateRadioField(
       ?name 'EnableEddyRadio
       ?choices '("on" "off")
       ?prompt "Turn Eddy on/off:"
       ?value "off"
       ?callback list("EddyEnable(t)" "EddyEnable(nil)")
       ) 

       
    procedure(EddyEnable(bool)
     myForm->EddyTextField1->editable=bool
     myForm->EddyTextField2->editable=bool

    writing this way makes pretty ugly code, so my question is if there a way to write the callback inline, something like that :

     EnableEddyRadioField = hiCreateRadioField(
       ?name 'EnableEddyRadio
       ?choices '("on" "off")
       ?prompt "Turn Eddy on/off:"
       ?value "off"
       ?callback list(
        (myForm->EddyTextField1->editable=t myForm->EddyTextField1->editable=t)
        (myForm->EddyTextField1->editable=nil myForm->EddyTextField1->editable=nil)
       )
       

    Thanks !

    Filed under:
    • Post Points: 20
  • Wed, Apr 10 2013 12:59 AM

    • berndfi
    • Top 100 Contributor
    • Joined on Tue, Sep 11 2012
    • Neubiberg, Bavaria
    • Posts 67
    • Points 1,255
    Re: How to write inline callback methods Reply

    To separate code into procedural pices is in my opinion not uggly,

    but here is an inline example.

     

    procedure( BFcreateEddyForm( )
        let( ( eddyStringField eddyRadioField )
            
    ;; creating the fields
        eddyStringField =
            hiCreateStringField(
                ?name       'eddyStringField
                ?prompt     "Eddy Text:"
                ?editable   nil
                )
                
        eddyRadioField =
            hiCreateRadioField(
                ?name       'eddyRadioField
                ?choices    '( "On" "Off" )
                ?prompt     "Turn Eddy On/Off:"
                ?value      "Off"
                ?callback   list(
                                "hiGetCurrentForm( )->eddyStringField->editable = t"  
                                "hiGetCurrentForm( )->eddyStringField->editable = nil"
                            )
            )
          
    ;; creating the form
        hiCreateAppForm(
            ?name       '__eddyForm__  
            ?formTitle  "Eddy Form"
            ?initialSize list( 300 260 )
            ?fields     list(
                        list(
                            eddyStringField
                            15:5 250:25 120
                            )
                        list(
                            eddyRadioField
                            15:50 250:25 120
                            )
                        )
        )
            
    ) ;; close let
    ) ;; close procedure

    procedure( BFeddyForm( )

        unless( boundp( '__eddyForm__ ) && hiIsFormDisplayed( __eddyForm__ )
                BFcreateEddyForm( )
                )
                
        hiDisplayForm( __eddyForm__ )
     
    ) ;; close procedure
            

    • Post Points: 20
  • Wed, Apr 10 2013 1:17 AM

    Re: How to write inline callback methods Reply

     And in your case you have two commands you want to do - so your callback could be:

    "myForm->EddyTextField1->editable=t myForm->EddyTextField2->editable="

    i.e. space separate them.

    In addition, in the upcoming IC616 release you'll be able to specify the callbacks as function objects, so you can create a lambda function (an unnamed inline function) to do this. Note that you can't do this in IC615. For example (adapting Bernd's code):

    procedure( BFcreateEddyForm( )
         let( ( eddyStringField1 eddyStringField2 eddyRadioField )
             
     ;; creating the fields
         eddyStringField1 =
             hiCreateStringField(
                 ?name       'eddyStringField1
                 ?prompt     "Eddy Text 1:"
                 ?editable   nil
                 )
         eddyStringField2 =
             hiCreateStringField(
                 ?name       'eddyStringField2
                 ?prompt     "Eddy Text 2:"
                 ?editable   nil
                 )
                 
         eddyRadioField =
             hiCreateRadioField(
                 ?name       'eddyRadioField
                 ?choices    '( "On" "Off" )
                 ?prompt     "Turn Eddy On/Off:"
                 ?value      "Off"
                 ?callback   
                    list(
                        lambda((field scope selection)
                            let((editable)
                                editable=if(selection=="On" t nil)
                                hiGetCurrentForm()->eddyStringField1->editable=editable
                                hiGetCurrentForm()->eddyStringField2->editable=editable
                            )
                        )
                    )
             )
           
     ;; creating the form
         hiCreateAppForm(
             ?name       '__eddyForm__  
             ?formTitle  "Eddy Form"
             ?initialSize list( 300 260 )
             ?fields     list(
                         list(
                             eddyStringField1
                             15:5 250:25 120
                             )
                         list(
                             eddyStringField2
                             15:35 250:25 120
                             )
                         list(
                             eddyRadioField
                             15:80 250:25 120
                             )
                         )
         )
             
     ) ;; close let
     ) ;; close procedure
    
     procedure( BFeddyForm( )
    
         unless( boundp( '__eddyForm__ ) && hiIsFormDisplayed( __eddyForm__ )
                 BFcreateEddyForm( )
                 )
                 
         hiDisplayForm( __eddyForm__ )
      
     ) ;; close procedure

     

    • Post Points: 20
  • Wed, Apr 10 2013 4:30 AM

    Re: How to write inline callback methods Reply

     Thanks, that's exactly what I needed !

    • Post Points: 5
Page 1 of 1 (4 items)
Sort Posts:
Started by TauStudent at 09 Apr 2013 11:13 PM. Topic has 3 replies.