• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Grabbing form field values

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 11141
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Grabbing form field values

HLuo
HLuo over 3 years ago

The below code works fine and is a copy of the code that is in the manual for the skill function for hiCreateAppForm. 

My specific question is in regards to:

procedure( myformglb_cb( )

As per below, should the values of the fields from the form be global variables and just be grabbed like so?

Or is there some way to pass the arguments to the callback procedure? I tried to do myformglb_cb(strfldglb~>value boolfldglb~>value) in the callback but to no avail.

; Generate the form
procedure( myformcreateform()
if( !boundp(`myformglb) || (myformglb == nil) then
strfldglb = hiCreateStringField(
?name `strfldglb
?prompt "sample string field" ;;; FIELD1, a string type
?defValue "initial string"
?callback ""
?editable t
)
; Create a Boolean button for the form.
boolfldglb = hiCreateBooleanButton(
?name `boolfldglb
?buttonText "sample boolean field" ;;; FIELD2, a boolean type
?defValue t
?callback ""
)

myformglb = hiCreateAppForm(
?name `myformglb
?fields list(strfldglb boolfldglb)
?formTitle "My first Form"
?callback "myformglb_cb()"
?buttonLayout `OKCancel
)
)
myformglb
)

; Display the form
procedure( myformdisplayform()
myformcreateform() ;;; Creation and Display are separate
hiDisplayForm(`myformglb)
)
; Check the current state of the form
;hiIsFormDisplayed(myformglb)
;myformdisplayform()
;hiIsFormDisplayed(myformglb)

procedure( myformglb_cb( )
testString = strfldglb~>value
sampleBoolean = boolfldglb~>value
printf("String '%s' boolean '%A'\n" testString sampleBoolean)
)

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    The example in the documentation is pretty poor - I will get tech pubs to improve it (I'd not noticed how bad it was as I'd not looked at it for some time). In general:

    1. Form fields do not need to be global - it's only the main form variable that must be global (this is so that an expression can be generated to reference the form from the global scope)
    2. You should access the form fields via the form variable itself rather than directly through the field variable.
    3. You can avoid referring to the global form variable by specifying the form callback as the function name, then it will automatically pass the form data structure to the callback. Alternatively you could have just used myformglb->strfld->value (in my updated code below) in the callback - i.e. via the form global variable

    I've updated the code to use local variables for the fields (I also changed it to use camel case for the function names consistently for style reasons):

    ;****************************************
    ;Sample form and fields
    ;****************************************
    ; Create string entry for the form. 
    procedure( myformDefineFields()
      let((strfld boolfld)
        strfld = hiCreateStringField(
          ?name 'strfld
          ?prompt "sample string field"    ;;; FIELD1, a string type
          ?defValue "initial string"
      ;    ?callback "my_strfld_cb()"
          ?editable t
      )
        ; Create a Boolean button for the form. 
        boolfld = hiCreateBooleanButton(
          ?name 'boolfld
          ?buttonText "sample boolean field"        ;;; FIELD2, a boolean type
          ?defValue t
      ;    ?callback "my_boolfld_cb()"
        )
        list( strfld boolfld )
      )
    )
    ; Generate the form
    procedure( myformCreateForm()
      if( !boundp(`myformglb) || (myformglb == nil)
        then
        myformglb = hiCreateAppForm(
          ?name `myformglb
          ?fields myformDefineFields()
          ?formTitle "My first Form"
          ?callback 'myformglb_cb
          ?buttonLayout `OKCancel
        )
      )
      myformglb
    )
    
    procedure(myformglb_cb(form)
      printf("Field values are: %s and %L\n" form->strfld->value form->boolfld->value)
    )
    
    ; Display the form
    procedure( myformDisplayForm()
      myformCreateForm()    ;;; Creation and Display are separate
      hiDisplayForm(`myformglb)
    )
    
    myformDisplayForm()

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • HLuo
    HLuo over 3 years ago in reply to Andrew Beckett

    Hi Andrew,

    That's super helpful!

    Thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information